File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -552,3 +552,47 @@ def test_partial_string_annotations_with_future_annotations(self):
552
552
def f() -> Optional['Queue[str]']:
553
553
return None
554
554
""" )
555
+
556
+ def test_idomiatic_typing_guards (self ):
557
+ # typing.TYPE_CHECKING: python3.5.3+
558
+ self .flakes ("""
559
+ from typing import TYPE_CHECKING
560
+
561
+ if TYPE_CHECKING:
562
+ from t import T
563
+
564
+ def f(): # type: () -> T
565
+ pass
566
+ """ )
567
+ # False: the old, more-compatible approach
568
+ self .flakes ("""
569
+ if False:
570
+ from t import T
571
+
572
+ def f(): # type: () -> T
573
+ pass
574
+ """ )
575
+ # some choose to assign a constant and do it that way
576
+ self .flakes ("""
577
+ MYPY = False
578
+
579
+ if MYPY:
580
+ from t import T
581
+
582
+ def f(): # type: () -> T
583
+ pass
584
+ """ )
585
+
586
+ def test_typing_guard_for_protocol (self ):
587
+ self .flakes ("""
588
+ from typing import TYPE_CHECKING
589
+
590
+ if TYPE_CHECKING:
591
+ from typing import Protocol
592
+ else:
593
+ Protocol = object
594
+
595
+ class C(Protocol):
596
+ def f(): # type: () -> int
597
+ pass
598
+ """ )
You can’t perform that action at this time.
0 commit comments