@@ -7318,63 +7318,58 @@ def test_type_params_possibilities(self):
73187318 with self .assertRaisesRegex (TypeError , "type_params must be a tuple" ):
73197319 TypeAliasType ("InvalidTypeParams" , List [T ], type_params = [T ])
73207320
7321- # Regression test assure compatibility with typing.TypeVar
7321+ # Regression test to assure compatibility with typing.TypeVar
73227322 typing_T = typing .TypeVar ('T' )
73237323 with self .subTest (type_params = "typing.TypeVar" ):
73247324 TypeAliasType ("TypingTypeParams" , List [typing_T ], type_params = (typing_T ,))
73257325
7326- # Test default order
7326+ # Test default order and other invalid inputs
73277327 T_default = TypeVar ('T_default' , default = int )
73287328 Ts = TypeVarTuple ('Ts' )
73297329 Ts_default = TypeVarTuple ('Ts_default' , default = Unpack [Tuple [str , int ]])
73307330 P = ParamSpec ('P' )
73317331 P_default = ParamSpec ('P_default' , default = [str , int ])
7332- P_default2 = ParamSpec ('P_default2' , default = ... )
7332+ P_default2 = ParamSpec ('P_default2' , default = P_default )
73337333
73347334 ok_cases = [
73357335 (T , T_default ),
73367336 (T , Ts_default ),
7337- (T , T_default , Ts_default ),
73387337 (T , P , Ts ),
7339- (T , P , Ts_default ),
7338+ (P , T_default , Ts_default ),
7339+ (Ts , P , Ts_default ),
73407340 (T , P_default ),
73417341 (T , P_default , T_default ),
73427342 (T , P_default , Ts_default ),
73437343 (T , Ts_default , P_default ),
73447344 (T , P_default , P_default2 ),
73457345 ]
73467346 invalid_cases = [
7347- (T_default , T ),
7348- (Ts_default , T ),
7349-
7350- # TypeVar after TypeVarTuple
7347+ ((T_default , T ), f"non-default type parameter { T !r} follows default" ),
7348+ ((P_default , P ), f"non-default type parameter { P !r} follows default" ),
7349+ ((Ts_default , Ts ), f"non-default type parameter { Ts !r} follows default" ),
7350+
7351+ # Potentially add invalid inputs, e.g. literals or classes
7352+ # depends on upstream
7353+ ((1 ,), "Expected a type param, got 1" ),
7354+ ((str ,), f"Expected a type param, got { str !r} " ),
7355+
73517356 # "TypeVars with defaults cannot immediately follow TypeVarTuples"
7357+ # is currently not enfored for the type statement, only for Generics
73527358 # (T, Ts, T_default),
73537359 # (T, Ts_default, T_default),
7354-
7355- # Two TypeVarTuples in a row, should the reverse be also invalid?
7356- (T , Ts_default , Ts ),
7357-
7358- (P_default , T ),
7359- (P_default , Ts ),
7360-
7361- # Double defintion
7360+
7361+ # Double use; however T2 = T; (T, T2) would likely be fine for a type checker
73627362 # (T, T)
73637363 # (Ts, *Ts)
73647364 # (P, **P)
7365-
7366- # Potentially add invalid inputs, e.g. literals or classes
7367- # depends on upstream
7368- # (1,)
7369- # (str,)
73707365 ]
73717366
73727367 for case in ok_cases :
73737368 with self .subTest (type_params = case ):
73747369 TypeAliasType ("OkCase" , List [T ], type_params = case )
7375- for case in invalid_cases :
7370+ for case , msg in invalid_cases :
73767371 with self .subTest (type_params = case ):
7377- with self .assertRaises (TypeError ):
7372+ with self .assertRaisesRegex (TypeError , msg ):
73787373 TypeAliasType ("InvalidCase" , List [T ], type_params = case )
73797374
73807375class DocTests (BaseTestCase ):
0 commit comments