@@ -100,16 +100,6 @@ def _in_type_checking_block(self, node: ast.AST) -> bool:
100100 if not self .type_checking_blocks and not self .empty_type_checking_blocks :
101101 return False
102102
103- # The list of empty type checking blocks is maintained for TC005
104- # If we find an import within one of these, we simply move it into self.type_checking_blocks
105- for index , empty_type_checking_block in enumerate (list (self .empty_type_checking_blocks )):
106- if empty_type_checking_block [0 ] <= node .lineno <= empty_type_checking_block [1 ]:
107- if isinstance (node , (ast .Import , ast .ImportFrom )):
108- self .type_checking_blocks .append (empty_type_checking_block )
109- self .empty_type_checking_blocks .pop (index )
110- else :
111- return True
112-
113103 return any (
114104 type_checking_block [0 ] <= node .lineno <= type_checking_block [1 ]
115105 for type_checking_block in self .type_checking_blocks + self .empty_type_checking_blocks
@@ -126,9 +116,11 @@ def visit_If(self, node: ast.If) -> Any:
126116 # Just set the lineno of the first element in the else block - 1
127117 start_of_else_block = node .orelse [0 ].lineno - 1
128118
129- # empty_type_checking_blocks' items are moved to self.type_checking_blocks
130- # as soon as we discover an import within one of the "empty" blocks
131- if (node .end_lineno or node .lineno ) - node .lineno == 1 :
119+ # Type checking blocks that only contain 'pass' are appended to an empty-type-checking-block list
120+ # and flagged with TC005 errors.
121+ if ((node .end_lineno or node .lineno ) - node .lineno == 1 ) and (
122+ len (node .body ) == 1 and isinstance (node .body [0 ], ast .Pass )
123+ ):
132124 self .empty_type_checking_blocks .append (
133125 (node .lineno , start_of_else_block or node .end_lineno or node .lineno , node .col_offset )
134126 )
0 commit comments