summaryrefslogtreecommitdiff
path: root/pyflakes/test/test_type_annotations.py
diff options
context:
space:
mode:
Diffstat (limited to 'pyflakes/test/test_type_annotations.py')
-rw-r--r--pyflakes/test/test_type_annotations.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index abe5473..eff222b 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -263,6 +263,14 @@ class TestTypeAnnotations(TestCase):
class A: pass
''')
self.flakes('''
+ T: object
+ def f(t: T): pass
+ ''', m.UndefinedName)
+ self.flakes('''
+ T: object
+ def g(t: 'T'): pass
+ ''')
+ self.flakes('''
a: 'A B'
''', m.ForwardAnnotationSyntaxError)
self.flakes('''
@@ -275,6 +283,26 @@ class TestTypeAnnotations(TestCase):
a: 'a: "A"'
''', m.ForwardAnnotationSyntaxError)
+ @skipIf(version_info < (3, 6), 'new in Python 3.6')
+ def test_unused_annotation(self):
+ # Unused annotations are fine in module and class scope
+ self.flakes('''
+ x: int
+ class Cls:
+ y: int
+ ''')
+ # TODO: this should print a UnusedVariable message
+ self.flakes('''
+ def f():
+ x: int
+ ''')
+ # This should only print one UnusedVariable message
+ self.flakes('''
+ def f():
+ x: int
+ x = 3
+ ''', m.UnusedVariable)
+
@skipIf(version_info < (3, 5), 'new in Python 3.5')
def test_annotated_async_def(self):
self.flakes('''
@@ -300,6 +328,13 @@ class TestTypeAnnotations(TestCase):
class B: pass
''', m.UndefinedName)
+ self.flakes('''
+ from __future__ import annotations
+ T: object
+ def f(t: T): pass
+ def g(t: 'T'): pass
+ ''')
+
def test_typeCommentsMarkImportsAsUsed(self):
self.flakes("""
from mod import A, B, C, D, E, F, G