Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions pyflakes/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,3 +552,47 @@ def test_partial_string_annotations_with_future_annotations(self):
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
""")