5353 captured_stderr , cpython_only , infinite_recursion , requires_docstrings , import_helper , run_code ,
5454 EqualToForwardRef ,
5555)
56- from test .typinganndata import ann_module695 , mod_generics_cache , _typed_dict_helper
56+ from test .typinganndata import (
57+ ann_module695 , mod_generics_cache , _typed_dict_helper ,
58+ ann_module , ann_module2 , ann_module3 , ann_module5 , ann_module6 , ann_module8
59+ )
5760
5861
5962CANNOT_SUBCLASS_TYPE = 'Cannot subclass special typing classes'
@@ -377,6 +380,7 @@ def test_alias(self):
377380 self .assertEqual (get_args (alias_2 ), (LiteralString ,))
378381 self .assertEqual (get_args (alias_3 ), (LiteralString ,))
379382
383+
380384class TypeVarTests (BaseTestCase ):
381385 def test_basic_plain (self ):
382386 T = TypeVar ('T' )
@@ -629,7 +633,7 @@ class TypeParameterDefaultsTests(BaseTestCase):
629633 def test_typevar (self ):
630634 T = TypeVar ('T' , default = int )
631635 self .assertEqual (T .__default__ , int )
632- self .assertTrue (T .has_default ())
636+ self .assertIs (T .has_default (), True )
633637 self .assertIsInstance (T , TypeVar )
634638
635639 class A (Generic [T ]): ...
@@ -639,19 +643,19 @@ def test_typevar_none(self):
639643 U = TypeVar ('U' )
640644 U_None = TypeVar ('U_None' , default = None )
641645 self .assertIs (U .__default__ , NoDefault )
642- self .assertFalse (U .has_default ())
646+ self .assertIs (U .has_default (), False )
643647 self .assertIs (U_None .__default__ , None )
644- self .assertTrue (U_None .has_default ())
648+ self .assertIs (U_None .has_default (), True )
645649
646650 class X [T ]: ...
647651 T , = X .__type_params__
648652 self .assertIs (T .__default__ , NoDefault )
649- self .assertFalse (T .has_default ())
653+ self .assertIs (T .has_default (), False )
650654
651655 def test_paramspec (self ):
652656 P = ParamSpec ('P' , default = (str , int ))
653657 self .assertEqual (P .__default__ , (str , int ))
654- self .assertTrue (P .has_default ())
658+ self .assertIs (P .has_default (), True )
655659 self .assertIsInstance (P , ParamSpec )
656660
657661 class A (Generic [P ]): ...
@@ -664,19 +668,19 @@ def test_paramspec_none(self):
664668 U = ParamSpec ('U' )
665669 U_None = ParamSpec ('U_None' , default = None )
666670 self .assertIs (U .__default__ , NoDefault )
667- self .assertFalse (U .has_default ())
671+ self .assertIs (U .has_default (), False )
668672 self .assertIs (U_None .__default__ , None )
669- self .assertTrue (U_None .has_default ())
673+ self .assertIs (U_None .has_default (), True )
670674
671675 class X [** P ]: ...
672676 P , = X .__type_params__
673677 self .assertIs (P .__default__ , NoDefault )
674- self .assertFalse (P .has_default ())
678+ self .assertIs (P .has_default (), False )
675679
676680 def test_typevartuple (self ):
677681 Ts = TypeVarTuple ('Ts' , default = Unpack [Tuple [str , int ]])
678682 self .assertEqual (Ts .__default__ , Unpack [Tuple [str , int ]])
679- self .assertTrue (Ts .has_default ())
683+ self .assertIs (Ts .has_default (), True )
680684 self .assertIsInstance (Ts , TypeVarTuple )
681685
682686 class A (Generic [Unpack [Ts ]]): ...
@@ -762,14 +766,14 @@ def test_typevartuple_none(self):
762766 U = TypeVarTuple ('U' )
763767 U_None = TypeVarTuple ('U_None' , default = None )
764768 self .assertIs (U .__default__ , NoDefault )
765- self .assertFalse (U .has_default ())
769+ self .assertIs (U .has_default (), False )
766770 self .assertIs (U_None .__default__ , None )
767- self .assertTrue (U_None .has_default ())
771+ self .assertIs (U_None .has_default (), True )
768772
769773 class X [** Ts ]: ...
770774 Ts , = X .__type_params__
771775 self .assertIs (Ts .__default__ , NoDefault )
772- self .assertFalse (Ts .has_default ())
776+ self .assertIs (Ts .has_default (), False )
773777
774778 def test_no_default_after_non_default (self ):
775779 DefaultStrT = TypeVar ('DefaultStrT' , default = str )
@@ -1170,7 +1174,6 @@ class C(Generic[*Ts]): pass
11701174 )
11711175
11721176
1173-
11741177class UnpackTests (BaseTestCase ):
11751178
11761179 def test_accepts_single_type (self ):
@@ -2186,8 +2189,8 @@ def test_cannot_instantiate(self):
21862189 type (u )()
21872190
21882191 def test_union_generalization (self ):
2189- self .assertFalse (Union [str , typing .Iterable [int ]] == str )
2190- self .assertFalse (Union [str , typing .Iterable [int ]] == typing .Iterable [int ])
2192+ self .assertNotEqual (Union [str , typing .Iterable [int ]], str )
2193+ self .assertNotEqual (Union [str , typing .Iterable [int ]], typing .Iterable [int ])
21912194 self .assertIn (str , Union [str , typing .Iterable [int ]].__args__ )
21922195 self .assertIn (typing .Iterable [int ], Union [str , typing .Iterable [int ]].__args__ )
21932196
@@ -2603,6 +2606,7 @@ def test_errors(self):
26032606 with self .assertRaisesRegex (TypeError , "few arguments for" ):
26042607 C1 [int ]
26052608
2609+
26062610class TypingCallableTests (BaseCallableTests , BaseTestCase ):
26072611 Callable = typing .Callable
26082612
@@ -2780,6 +2784,7 @@ class Coordinate(Protocol):
27802784 x : int
27812785 y : int
27822786
2787+
27832788@runtime_checkable
27842789class Point (Coordinate , Protocol ):
27852790 label : str
@@ -4120,12 +4125,12 @@ class PG(Protocol[T]):
41204125 def meth (self ):
41214126 pass
41224127
4123- self .assertTrue (P ._is_protocol )
4124- self .assertTrue (PR ._is_protocol )
4125- self .assertTrue (PG ._is_protocol )
4126- self .assertFalse (P ._is_runtime_protocol )
4127- self .assertTrue (PR ._is_runtime_protocol )
4128- self .assertTrue (PG [int ]._is_protocol )
4128+ self .assertIs (P ._is_protocol , True )
4129+ self .assertIs (PR ._is_protocol , True )
4130+ self .assertIs (PG ._is_protocol , True )
4131+ self .assertIs (P ._is_runtime_protocol , False )
4132+ self .assertIs (PR ._is_runtime_protocol , True )
4133+ self .assertIs (PG [int ]._is_protocol , True )
41294134 self .assertEqual (typing ._get_protocol_attrs (P ), {'meth' })
41304135 self .assertEqual (typing ._get_protocol_attrs (PR ), {'x' })
41314136 self .assertEqual (frozenset (typing ._get_protocol_attrs (PG )),
@@ -5838,6 +5843,7 @@ def test_no_isinstance(self):
58385843 with self .assertRaises (TypeError ):
58395844 issubclass (int , ClassVar )
58405845
5846+
58415847class FinalTests (BaseTestCase ):
58425848
58435849 def test_basics (self ):
@@ -6043,7 +6049,7 @@ def wrong(self) -> int:
60436049
60446050 instance = Child ()
60456051 self .assertEqual (instance .correct , 2 )
6046- self .assertTrue (Child .correct .fget .__override__ )
6052+ self .assertIs (Child .correct .fget .__override__ , True )
60476053 self .assertEqual (instance .wrong , 2 )
60486054 self .assertNotHasAttr (Child .wrong , "__override__" )
60496055 self .assertNotHasAttr (Child .wrong .fset , "__override__" )
@@ -6084,9 +6090,9 @@ def on_bottom(self, a: int) -> int:
60846090
60856091 instance = WithOverride ()
60866092 self .assertEqual (instance .on_top (1 ), 2 )
6087- self .assertTrue (instance .on_top .__override__ )
6093+ self .assertIs (instance .on_top .__override__ , True )
60886094 self .assertEqual (instance .on_bottom (1 ), 3 )
6089- self .assertTrue (instance .on_bottom .__override__ )
6095+ self .assertIs (instance .on_bottom .__override__ , True )
60906096
60916097
60926098class CastTests (BaseTestCase ):
@@ -6124,8 +6130,6 @@ def test_errors(self):
61246130
61256131
61266132# We need this to make sure that `@no_type_check` respects `__module__` attr:
6127- from test .typinganndata import ann_module8
6128-
61296133@no_type_check
61306134class NoTypeCheck_Outer :
61316135 Inner = ann_module8 .NoTypeCheck_Outer .Inner
@@ -6193,7 +6197,7 @@ class D:
61936197
61946198 for klass in [A , A .B , A .B .C , A .D ]:
61956199 with self .subTest (klass = klass ):
6196- self .assertTrue (klass .__no_type_check__ )
6200+ self .assertIs (klass .__no_type_check__ , True )
61976201 self .assertEqual (get_type_hints (klass ), {})
61986202
61996203 for not_modified in [Other , B ]:
@@ -6210,19 +6214,19 @@ def st(x: int) -> int: ...
62106214 @classmethod
62116215 def cl (cls , y : int ) -> int : ...
62126216
6213- self .assertTrue (Some .st .__no_type_check__ )
6217+ self .assertIs (Some .st .__no_type_check__ , True )
62146218 self .assertEqual (get_type_hints (Some .st ), {})
6215- self .assertTrue (Some .cl .__no_type_check__ )
6219+ self .assertIs (Some .cl .__no_type_check__ , True )
62166220 self .assertEqual (get_type_hints (Some .cl ), {})
62176221
62186222 def test_no_type_check_other_module (self ):
6219- self .assertTrue (NoTypeCheck_Outer .__no_type_check__ )
6223+ self .assertIs (NoTypeCheck_Outer .__no_type_check__ , True )
62206224 with self .assertRaises (AttributeError ):
62216225 ann_module8 .NoTypeCheck_Outer .__no_type_check__
62226226 with self .assertRaises (AttributeError ):
62236227 ann_module8 .NoTypeCheck_Outer .Inner .__no_type_check__
62246228
6225- self .assertTrue (NoTypeCheck_WithFunction .__no_type_check__ )
6229+ self .assertIs (NoTypeCheck_WithFunction .__no_type_check__ , True )
62266230 with self .assertRaises (AttributeError ):
62276231 ann_module8 .NoTypeCheck_function .__no_type_check__
62286232
@@ -6247,7 +6251,7 @@ class A:
62476251 # Corner case: `lambda` is both an assignment and a function:
62486252 bar : Callable [[int ], int ] = lambda arg : arg
62496253
6250- self .assertTrue (A .bar .__no_type_check__ )
6254+ self .assertIs (A .bar .__no_type_check__ , True )
62516255 self .assertEqual (get_type_hints (A .bar ), {})
62526256
62536257 def test_no_type_check_TypeError (self ):
@@ -6334,6 +6338,7 @@ def test_collect_parameters(self):
63346338 typing ._collect_parameters
63356339 self .assertEqual (cm .filename , __file__ )
63366340
6341+ @cpython_only
63376342 def test_lazy_import (self ):
63386343 import_helper .ensure_lazy_imports ("typing" , {
63396344 "warnings" ,
@@ -6449,10 +6454,6 @@ def test_overload_registry_repeated(self):
64496454 self .assertEqual (list (get_overloads (impl )), overloads )
64506455
64516456
6452- from test .typinganndata import (
6453- ann_module , ann_module2 , ann_module3 , ann_module5 , ann_module6 ,
6454- )
6455-
64566457T_a = TypeVar ('T_a' )
64576458
64586459class AwaitableWrapper (typing .Awaitable [T_a ]):
@@ -6665,8 +6666,8 @@ def test_respect_no_type_check(self):
66656666 class NoTpCheck :
66666667 class Inn :
66676668 def __init__ (self , x : 'not a type' ): ...
6668- self .assertTrue (NoTpCheck .__no_type_check__ )
6669- self .assertTrue (NoTpCheck .Inn .__init__ .__no_type_check__ )
6669+ self .assertIs (NoTpCheck .__no_type_check__ , True )
6670+ self .assertIs (NoTpCheck .Inn .__init__ .__no_type_check__ , True )
66706671 self .assertEqual (gth (ann_module2 .NTC .meth ), {})
66716672 class ABase (Generic [T ]):
66726673 def meth (x : int ): ...
@@ -10196,6 +10197,7 @@ def test_var_substitution(self):
1019610197 self .assertEqual (C [Concatenate [str , P2 ]], Concatenate [int , str , P2 ])
1019710198 self .assertEqual (C [...], Concatenate [int , ...])
1019810199
10200+
1019910201class TypeGuardTests (BaseTestCase ):
1020010202 def test_basics (self ):
1020110203 TypeGuard [int ] # OK
0 commit comments