diff options
-rw-r--r-- | pyflakes/checker.py | 2 | ||||
-rw-r--r-- | pyflakes/test/test_type_annotations.py | 7 |
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 |