File tree 3 files changed +17
-1
lines changed
tests/functional/u/undefined
3 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -58,6 +58,10 @@ Release date: TBA
58
58
59
59
Closes #3614
60
60
61
+ * Fix crash with ``AssignAttr`` in ``if TYPE_CHECKING`` blocks.
62
+
63
+ Closes #5111
64
+
61
65
62
66
What's New in Pylint 2.11.1?
63
67
============================
Original file line number Diff line number Diff line change @@ -1536,7 +1536,9 @@ def _is_variable_violation(
1536
1536
for definition in defstmt_parent .orelse :
1537
1537
if isinstance (definition , nodes .Assign ):
1538
1538
defined_in_or_else = any (
1539
- target .name == name for target in definition .targets
1539
+ target .name == name
1540
+ for target in definition .targets
1541
+ if isinstance (target , nodes .AssignName )
1540
1542
)
1541
1543
if defined_in_or_else :
1542
1544
break
Original file line number Diff line number Diff line change @@ -328,3 +328,13 @@ def decorated3(x):
328
328
@decorator (x * x * y for x in range (3 )) # [undefined-variable]
329
329
def decorated4 (x ):
330
330
print (x )
331
+
332
+
333
+ # https://github.com/PyCQA/pylint/issues/5111
334
+ # AssignAttr in orelse block of 'TYPE_CHECKING' shouldn't crash
335
+ # Name being assigned must be imported in orelse block
336
+ if TYPE_CHECKING :
337
+ pass
338
+ else :
339
+ from types import GenericAlias
340
+ object ().__class_getitem__ = classmethod (GenericAlias )
You can’t perform that action at this time.
0 commit comments