summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2023-01-31 13:45:58 -0500
committerGitHub <noreply@github.com>2023-01-31 13:45:58 -0500
commite19886e583637a7e2eec428cc036094b9630f2d0 (patch)
tree5dad34e1dc3321b34c28339e175e02c8fbde6306
parente9324649874a7124a08c3826d4cf78a4dc3aa32c (diff)
downloadpyflakes-e19886e583637a7e2eec428cc036094b9630f2d0.tar.gz
fix accessed global annotation being redefined in a local scope (#765)
-rw-r--r--pyflakes/checker.py2
-rw-r--r--pyflakes/test/test_type_annotations.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 4d778a8..e654afa 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1068,7 +1068,7 @@ class Checker:
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):
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index f0fd3b9..396d676 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -367,6 +367,13 @@ class TestTypeAnnotations(TestCase):
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