summaryrefslogtreecommitdiff
path: root/pyflakes/test/test_type_annotations.py
diff options
context:
space:
mode:
authorLaurent Kadian <17257425+lkadian@users.noreply.github.com>2022-02-13 11:32:09 -0500
committerGitHub <noreply@github.com>2022-02-13 11:32:09 -0500
commit84da8cdaad574df7e692dff06ab561acc63d521c (patch)
treeea41b85876cbaee9273de6b0567409cb6499efc6 /pyflakes/test/test_type_annotations.py
parent1fae3dea5108a006d35da9e9ab785ca1ed1bc998 (diff)
downloadpyflakes-84da8cdaad574df7e692dff06ab561acc63d521c.tar.gz
support TypeAlias annotations (#679)
For assignments with `TypeAlias` as annotation, handle the value as an annotation also. Avoids incorrectly detecting `Bar` as unused in `x: TypeAlias = 'Bar'`.
Diffstat (limited to 'pyflakes/test/test_type_annotations.py')
-rw-r--r--pyflakes/test/test_type_annotations.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py
index f3b6c24..3b6d5e7 100644
--- a/pyflakes/test/test_type_annotations.py
+++ b/pyflakes/test/test_type_annotations.py
@@ -301,6 +301,46 @@ class TestTypeAnnotations(TestCase):
''', m.ForwardAnnotationSyntaxError)
@skipIf(version_info < (3, 6), 'new in Python 3.6')
+ def test_TypeAlias_annotations(self):
+ self.flakes("""
+ from typing_extensions import TypeAlias
+ from foo import Bar
+
+ bar: TypeAlias = Bar
+ """)
+ self.flakes("""
+ from typing_extensions import TypeAlias
+ from foo import Bar
+
+ bar: TypeAlias = 'Bar'
+ """)
+ self.flakes("""
+ from typing_extensions import TypeAlias
+ from foo import Bar
+
+ class A:
+ bar: TypeAlias = Bar
+ """)
+ self.flakes("""
+ from typing_extensions import TypeAlias
+ from foo import Bar
+
+ class A:
+ bar: TypeAlias = 'Bar'
+ """)
+ self.flakes("""
+ from typing_extensions import TypeAlias
+
+ bar: TypeAlias
+ """)
+ self.flakes("""
+ from typing_extensions import TypeAlias
+ from foo import Bar
+
+ bar: TypeAlias
+ """, m.UnusedImport)
+
+ @skipIf(version_info < (3, 6), 'new in Python 3.6')
def test_annotating_an_import(self):
self.flakes('''
from a import b, c