File tree Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Expand file tree Collapse file tree 3 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -12,5 +12,10 @@ matrix:
12
12
dist : xenial
13
13
- python : nightly
14
14
dist : xenial
15
+ # TODO: https://bugs.python.org/issue40334
16
+ # the PEG parser is currently broken in some cases
17
+ allow_failures :
18
+ - python : nightly
19
+ dist : xenial
15
20
install : pip install tox
16
21
script : tox -e py
Original file line number Diff line number Diff line change @@ -449,6 +449,8 @@ def evaluate(source):
449
449
with self .makeTempFile (source ) as sourcePath :
450
450
if PYPY :
451
451
message = 'end of file (EOF) while scanning triple-quoted string literal'
452
+ elif sys .version_info >= (3 , 9 ):
453
+ message = 'invalid string prefix'
452
454
else :
453
455
message = 'invalid syntax'
454
456
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