@@ -7227,7 +7227,6 @@ def test_alias_types_and_substitutions(self):
72277227 ... : (),
72287228 T2 : (T2 ,),
72297229 Union [int , List [T2 ]] : (T2 ,),
7230- Ts : (Ts ,),
72317230 Tuple [int , str ] : (),
72327231 Tuple [T , T_default , T2 ] : (T , T_default , T2 ),
72337232 Tuple [Unpack [Ts ]] : (Ts ,),
@@ -7237,11 +7236,16 @@ def test_alias_types_and_substitutions(self):
72377236 TypeAliasType ("NestedAlias" , List [T ], type_params = (T ,))[T2 ] : (T2 ,),
72387237 }
72397238 # currently a limitation, these args are no longer unpacked in 3.11
7240- test_argument_cases_311_plus = {
7241- Unpack [ Ts ] : ( Ts ,),
7239+ # also valid on 310 if GenericAlias is used
7240+ test_argument_cases_310_plus = {
72427241 Unpack [Tuple [int , T2 ]] : (T2 ,),
72437242 Concatenate [int , P ] : (P ,),
7243+ Unpack [Ts ] : (Ts ,),
72447244 }
7245+ test_argument_cases_311_plus = {
7246+ Ts : (Ts ,),
7247+ }
7248+ test_argument_cases .update (test_argument_cases_310_plus )
72457249 test_argument_cases .update (test_argument_cases_311_plus )
72467250
72477251 test_alias_cases = [
@@ -7280,8 +7284,10 @@ def test_alias_types_and_substitutions(self):
72807284 self .assertEqual (subscripted .__parameters__ , ())
72817285 for expected_args , expected_parameters in test_argument_cases .items ():
72827286 with self .subTest (alias = alias , args = expected_args ):
7287+ if expected_args in test_argument_cases_310_plus and sys .version_info < (3 , 10 ):
7288+ self .skipTest ("args are unpacked before 3.11 or need GenericAlias" )
72837289 if expected_args in test_argument_cases_311_plus and sys .version_info < (3 , 11 ):
7284- self .skipTest ("args are unpacked before 3.11" )
7290+ self .skipTest ("Case is not valid before 3.11" )
72857291 self .assertEqual (get_args (alias [expected_args ]), (expected_args ,))
72867292 self .assertEqual (alias [expected_args ].__parameters__ , expected_parameters )
72877293
@@ -7397,20 +7403,15 @@ def test_callable_with_concatenate(self):
73977403
73987404 callable_concat = CallableP [Concatenate [int , P ]]
73997405 self .assertEqual (callable_concat .__parameters__ , (P ,))
7400- if TYPING_3_11_0 :
7401- concat_usage = callable_concat [str ]
7406+ concat_usage = callable_concat [str ]
7407+ with self .subTest ("get_args of Concatenate in TypeAliasType" ):
7408+ if sys .version_info < (3 , 10 , 2 ):
7409+ self .skipTest ("GenericAlias keeps Concatenate in __args__ prior to 3.10.2" )
74027410 self .assertEqual (get_args (concat_usage ), ((int , str ),))
7411+ with self .subTest ("Equality of parameter_expression without []" ):
7412+ if not TYPING_3_10_0 :
7413+ self .skipTest ("Nested list is invalid type form" )
74037414 self .assertEqual (concat_usage , callable_concat [[str ]])
7404- elif TYPING_3_10_0 :
7405- with self .assertRaises (TypeError , msg = "Parameters to generic types must be types" ):
7406- callable_concat [str ]
7407- concat_usage = callable_concat [[str ]]
7408- self .assertEqual (get_args (concat_usage ), (int , [str ]))
7409- else :
7410- with self .assertRaises (TypeError , msg = "Parameters to generic types must be types" ):
7411- callable_concat [[str ]]
7412- concat_usage = callable_concat [str ]
7413- self .assertEqual (get_args (concat_usage ), (int , str ))
74147415
74157416 @skipUnless (TYPING_3_11_0 , "__args__ behaves differently" )
74167417 def test_substitution_311_plus (self ):
@@ -7506,7 +7507,8 @@ def test_list_argument(self):
75067507 with self .assertRaises (TypeError , msg = "is not a generic class" ):
75077508 invalid_tupleT [str ]
75087509
7509- @skipIf (TYPING_3_11_0 , "Most cases are allowed in 3.11+" )
7510+ # The condition should align with the version of GeneriAlias usage in __getitem__
7511+ @skipIf (TYPING_3_9_0 , "Most cases are allowed in 3.11+ or with GenericAlias" )
75107512 def test_invalid_cases_before_3_11 (self ):
75117513 T = TypeVar ('T' )
75127514 ListOrSetT = TypeAliasType ("ListOrSetT" , Union [List [T ], Set [T ]], type_params = (T ,))
0 commit comments