From e19886e583637a7e2eec428cc036094b9630f2d0 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Tue, 31 Jan 2023 13:45:58 -0500 Subject: fix accessed global annotation being redefined in a local scope (#765) --- pyflakes/checker.py | 2 +- pyflakes/test/test_type_annotations.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1