Skip to content

Commit

Permalink
fix accessed global annotation being redefined in a local scope (#765)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored Jan 31, 2023
1 parent e932464 commit e19886e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyflakes/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ def handleNodeLoad(self, node, parent):

binding = scope.get(name, None)
if isinstance(binding, Annotation) and not self._in_postponed_annotation:
scope[name].used = True
scope[name].used = (self.scope, node)
continue

if name == 'print' and isinstance(binding, Builtin):
Expand Down
7 changes: 7 additions & 0 deletions pyflakes/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ def f():
x = 3
''', m.UnusedVariable)

def test_unused_annotation_in_outer_scope_reassigned_in_local_scope(self):
self.flakes('''
x: int
x.__dict__
def f(): x = 1
''', m.UndefinedName, m.UnusedVariable)

def test_unassigned_annotation_is_undefined(self):
self.flakes('''
name: str
Expand Down

0 comments on commit e19886e

Please sign in to comment.