Skip to content

Commit

Permalink
detect undefined name of variable defined by AnnAssign (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
asottile authored Sep 8, 2022
1 parent 7d6479e commit 4dcd92e
Show file tree
Hide file tree
Showing 2 changed files with 6 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 @@ -2265,7 +2265,6 @@ def EXCEPTHANDLER(self, node):
self.scope[node.name] = prev_definition

def ANNASSIGN(self, node):
self.handleNode(node.target, node)
self.handleAnnotation(node.annotation, node)
# If the assignment has value, handle the *value* now.
if node.value:
Expand All @@ -2274,6 +2273,7 @@ def ANNASSIGN(self, node):
self.handleAnnotation(node.value, node)
else:
self.handleNode(node.value, node)
self.handleNode(node.target, node)

def COMPARE(self, node):
left = node.left
Expand Down
5 changes: 5 additions & 0 deletions pyflakes/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ def g(t: 'T'): pass
a: 'a: "A"'
''', m.ForwardAnnotationSyntaxError)

def test_variable_annotation_references_self_name_undefined(self):
self.flakes("""
x: int = x
""", m.UndefinedName)

def test_TypeAlias_annotations(self):
self.flakes("""
from typing_extensions import TypeAlias
Expand Down

0 comments on commit 4dcd92e

Please sign in to comment.