diff options
-rw-r--r-- | pyflakes/test/test_type_annotations.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/pyflakes/test/test_type_annotations.py b/pyflakes/test/test_type_annotations.py index ed28127..abe5473 100644 --- a/pyflakes/test/test_type_annotations.py +++ b/pyflakes/test/test_type_annotations.py @@ -552,3 +552,47 @@ class TestTypeAnnotations(TestCase): def f() -> Optional['Queue[str]']: return None """) + + def test_idomiatic_typing_guards(self): + # typing.TYPE_CHECKING: python3.5.3+ + self.flakes(""" + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from t import T + + def f(): # type: () -> T + pass + """) + # False: the old, more-compatible approach + self.flakes(""" + if False: + from t import T + + def f(): # type: () -> T + pass + """) + # some choose to assign a constant and do it that way + self.flakes(""" + MYPY = False + + if MYPY: + from t import T + + def f(): # type: () -> T + pass + """) + + def test_typing_guard_for_protocol(self): + self.flakes(""" + from typing import TYPE_CHECKING + + if TYPE_CHECKING: + from typing import Protocol + else: + Protocol = object + + class C(Protocol): + def f(): # type: () -> int + pass + """) |