Skip to content

Commit e19886e

Browse files
authored
fix accessed global annotation being redefined in a local scope (#765)
1 parent e932464 commit e19886e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pyflakes/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,7 +1068,7 @@ def handleNodeLoad(self, node, parent):
10681068

10691069
binding = scope.get(name, None)
10701070
if isinstance(binding, Annotation) and not self._in_postponed_annotation:
1071-
scope[name].used = True
1071+
scope[name].used = (self.scope, node)
10721072
continue
10731073

10741074
if name == 'print' and isinstance(binding, Builtin):

pyflakes/test/test_type_annotations.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ def f():
367367
x = 3
368368
''', m.UnusedVariable)
369369

370+
def test_unused_annotation_in_outer_scope_reassigned_in_local_scope(self):
371+
self.flakes('''
372+
x: int
373+
x.__dict__
374+
def f(): x = 1
375+
''', m.UndefinedName, m.UnusedVariable)
376+
370377
def test_unassigned_annotation_is_undefined(self):
371378
self.flakes('''
372379
name: str

0 commit comments

Comments
 (0)