summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author秋葉 <ambiguous404@gmail.com>2019-07-03 09:37:22 +0800
committerSteven Myint <git@stevenmyint.com>2019-07-02 18:37:22 -0700
commit4a807d45f9dd47266c82035bf6e04508a77f0258 (patch)
treeb65a5fe0dc032b06500730cf07ba562f628401bb
parent0b163640274b15b74ac9a650cf24439b0205fc76 (diff)
downloadpyflakes-4a807d45f9dd47266c82035bf6e04508a77f0258.tar.gz
Fix return annotation is class level variable caused undefined (#448)
* fix annotation is class level variable caused undefined * update skipif condition
-rw-r--r--pyflakes/checker.py2
-rw-r--r--pyflakes/test/test_type_annotations.py20
2 files changed, 21 insertions, 1 deletions
diff --git a/pyflakes/checker.py b/pyflakes/checker.py
index 0e636c1..83f92aa 100644
--- a/pyflakes/checker.py
+++ b/pyflakes/checker.py
@@ -1480,7 +1480,7 @@ class Checker(object):
self.pushScope()
- self.handleChildren(node, omit='decorator_list')
+ self.handleChildren(node, omit=['decorator_list', 'returns'])
def checkUnusedAssignments():
"""
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index 03f70bb..9c34dcf 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -342,3 +342,23 @@ class TestTypeAnnotations(TestCase):
x = 1
# type: F
""")
+
+ @skipIf(version_info < (3,), 'new in Python 3')
+ def test_return_annotation_is_class_scope_variable(self):
+ self.flakes("""
+ from typing import TypeVar
+ class Test:
+ Y = TypeVar('Y')
+
+ def t(self, x: Y) -> Y:
+ return x
+ """)
+
+ @skipIf(version_info < (3,), 'new in Python 3')
+ def test_return_annotation_is_function_body_variable(self):
+ self.flakes("""
+ class Test:
+ def t(self) -> Y:
+ Y = 2
+ return Y
+ """, m.UndefinedName)