Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect undefined name of variable defined by AnnAssign #729

Merged
merged 1 commit into from Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyflakes/checker.py
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
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