@@ -5305,49 +5305,72 @@ class ProtoZ(Protocol[P]):
53055305 for klass in Z , ProtoZ :
53065306 with self .subTest (klass = klass .__name__ ):
53075307 # Note: For 3.10+ __args__ are nested tuples here ((int, ),) instead of (int, )
5308- G6 = klass [int , str , bool ]
5308+ G6 = klass [int , str , T ]
53095309 G6args = G6 .__args__ [0 ] if sys .version_info >= (3 , 10 ) else G6 .__args__
5310- self .assertEqual (G6args , (int , str , bool ))
5311- self .assertEqual (G6 .__parameters__ , ())
5310+ self .assertEqual (G6args , (int , str , T ))
53125311
53135312 # P = [int]
53145313 G7 = klass [int ]
53155314 G7args = G7 .__args__ [0 ] if sys .version_info >= (3 , 10 ) else G7 .__args__
53165315 self .assertEqual (G7args , (int ,))
53175316 self .assertEqual (G7 .__parameters__ , ())
53185317
5319- # P = [int, int, ...]
5320- G8 = klass [T , Concatenate [int , ...]]
5321- G8args = G8 .__args__ [0 ] if sys .version_info >= (3 , 10 ) else G8 .__args__
5322- self .assertEqual (G8args , (T , Concatenate [int , ...]))
5318+ G8 = klass [Concatenate [T , ...]]
5319+ self .assertEqual (G8 .__args__ , (Concatenate [T , ...], ))
53235320
5324- # P = [int, int, P_2]
5325- G9 = klass [int , Concatenate [T , P_2 ]]
5326- G9args = G9 .__args__ [0 ] if sys .version_info >= (3 , 10 ) else G9 .__args__
5327- self .assertEqual (G9args , (int , Concatenate [T , P_2 ]))
5321+ G9 = klass [Concatenate [T , P_2 ]]
5322+ self .assertEqual (G9 .__args__ , (Concatenate [T , P_2 ], ))
53285323
5329- with self .subTest ("Recursive ParamSpec Test A" ):
5324+ # This is an invalid form but useful for testing correct subsitution
5325+ G10 = klass [int , Concatenate [str , P ]]
5326+ G10args = G10 .__args__ [0 ] if sys .version_info >= (3 , 10 ) else G10 .__args__
5327+ self .assertEqual (G10args , (int , Concatenate [str , P ], ))
5328+
5329+ with self .subTest ("Check generic substitution" , klass = klass .__name__ ):
5330+ if sys .version_info < (3 , 10 ):
5331+ self .skipTest ("_ConcatenateGenericAlias not subscriptable" )
5332+ with self .assertRaisesRegex (TypeError , "Expected a list of types, an ellipsis, ParamSpec, or Concatenate" ):
5333+ G9 [int , int ]
5334+
5335+ with self .subTest ("Check list as parameter expression" , klass = klass .__name__ ):
5336+ if sys .version_info < (3 , 10 ):
5337+ self .skipTest ("Cannot pass non-types" )
5338+ G5 = klass [[int , str , T ]]
5339+ self .assertEqual (G5 .__args__ , ((int , str , T ),))
5340+ H9 = G9 [int , [T ]]
5341+
5342+ with self .subTest ("Check parametrization" , klass = klass .__name__ ):
53305343 if sys .version_info [:2 ] == (3 , 10 ):
53315344 self .skipTest ("Parameter detection fails in 3.10" )
53325345 with self .assertRaisesRegex (TypeError , f"Too few { things } " ):
53335346 G9 [int ] # for python 3.10 this has no parameters
5347+ self .assertEqual (G6 .__parameters__ , (T ,))
53345348 self .assertEqual (G8 .__parameters__ , (T ,))
53355349 self .assertEqual (G9 .__parameters__ , (T , P_2 ))
5350+ if sys .version_info >= (3 , 10 ): # skipped above
5351+ self .assertEqual (G5 .__parameters__ , (T ,))
5352+ self .assertEqual (H9 .__parameters__ , (T ,))
53365353
5337- with self .subTest ("Recursive ParamSpec Test B" ):
5354+ with self .subTest ("Check further substitution" , klass = klass .__name__ ):
5355+ if sys .version_info < (3 , 10 ):
5356+ self .skipTest ("_ConcatenateGenericAlias not subscriptable" )
53385357 if sys .version_info [:2 ] == (3 , 10 ):
53395358 self .skipTest ("Parameter detection fails in 3.10" )
53405359 if (3 , 11 , 0 ) <= sys .version_info [:3 ] < (3 , 11 , 3 ):
53415360 self .skipTest ("Wrong recursive substitution" )
53425361 H1 = G8 [int ]
5343- H2 = G8 [T ][int ]
5344- self .assertEqual (H2 .__parameters__ , ())
53455362 self .assertEqual (H1 .__parameters__ , ())
53465363 with self .assertRaisesRegex (TypeError , "not a generic class" ):
53475364 H1 [str ] # for python 3.11.0-3 this still has a parameter
5365+
5366+ H2 = G8 [T ][int ]
5367+ self .assertEqual (H2 .__parameters__ , ())
53485368 with self .assertRaisesRegex (TypeError , "not a generic class" ):
53495369 H2 [str ] # for python 3.11.0-3 this still has a parameter
53505370
5371+ H3 = G10 [int ]
5372+ self .assertEqual (H3 .__args__ , ((int , (str , int )),))
5373+
53515374 def test_pickle (self ):
53525375 global P , P_co , P_contra , P_default
53535376 P = ParamSpec ('P' )
0 commit comments