@@ -5316,37 +5316,24 @@ class ProtoZ(Protocol[P]):
53165316 self .assertEqual (G7args , (int ,))
53175317 self .assertEqual (G7 .__parameters__ , ())
53185318
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 , ...]))
5323-
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 ]))
5328-
5329- with self .subTest ("Recursive ParamSpec Test A" ):
5330- if sys .version_info [:2 ] == (3 , 10 ):
5331- self .skipTest ("Parameter detection fails in 3.10" )
5332- with self .assertRaisesRegex (TypeError , f"Too few { things } " ):
5333- G9 [int ] # for python 3.10 this has no parameters
5334- self .assertEqual (G8 .__parameters__ , (T ,))
5335- self .assertEqual (G9 .__parameters__ , (T , P_2 ))
5336-
5337- with self .subTest ("Recursive ParamSpec Test B" ):
5338- if sys .version_info [:2 ] == (3 , 10 ):
5339- self .skipTest ("Parameter detection fails in 3.10" )
5340- if (3 , 11 , 0 ) <= sys .version_info [:3 ] < (3 , 11 , 3 ):
5341- self .skipTest ("Wrong recursive substitution" )
5342- H1 = G8 [int ]
5343- H2 = G8 [T ][int ]
5344- self .assertEqual (H2 .__parameters__ , ())
5345- self .assertEqual (H1 .__parameters__ , ())
5346- with self .assertRaisesRegex (TypeError , "not a generic class" ):
5347- H1 [str ] # for python 3.11.0-3 this still has a parameter
5348- with self .assertRaisesRegex (TypeError , "not a generic class" ):
5349- H2 [str ] # for python 3.11.0-3 this still has a parameter
5319+ G8 = klass [Concatenate [T , ...]]
5320+ self .assertEqual (G8 .__args__ , (Concatenate [T , ...], ))
5321+ self .assertEqual (G8 .__parameters__ , (T ,))
5322+
5323+ G9 = klass [Concatenate [T , P_2 ]]
5324+ self .assertEqual (G9 .__args__ , (Concatenate [T , P_2 ],))
5325+ self .assertEqual (G9 .__parameters__ , (T , P_2 ))
5326+ with self .assertRaisesRegex (TypeError , f"Too few { things } " ):
5327+ G9 [int ]
5328+
5329+ H1 = G8 [int ]
5330+ H2 = G8 [T ][int ]
5331+ self .assertEqual (H2 .__parameters__ , ())
5332+ self .assertEqual (H1 .__parameters__ , ())
5333+ with self .assertRaisesRegex (TypeError , "not a generic class" ):
5334+ H1 [str ]
5335+ with self .assertRaisesRegex (TypeError , "not a generic class" ):
5336+ H2 [str ]
53505337
53515338 def test_pickle (self ):
53525339 global P , P_co , P_contra , P_default
@@ -5529,6 +5516,32 @@ def test_eq(self):
55295516 self .assertEqual (hash (C4 ), hash (C5 ))
55305517 self .assertNotEqual (C4 , C6 )
55315518
5519+ def test_substitution (self ):
5520+ T = TypeVar ('T' )
5521+ P = ParamSpec ('P' )
5522+ Ts = TypeVarTuple ("Ts" )
5523+
5524+ C1 = Concatenate [str , T , ...]
5525+ self .assertEqual (C1 [int ], Concatenate [str , int , ...])
5526+
5527+ C2 = Concatenate [str , P ]
5528+ self .assertEqual (C2 [...], Concatenate [str , ...])
5529+ self .assertEqual (C2 [int ], (str , int ))
5530+ U1 = Unpack [Tuple [int , str ]]
5531+ U2 = Unpack [Ts ]
5532+ self .assertEqual (C2 [U1 ], (str , int , str ))
5533+ self .assertEqual (C2 [U2 ], (str , Unpack [Ts ]))
5534+
5535+ if (3 , 12 , 0 ) <= sys .version_info < (3 , 12 , 4 ):
5536+ with self .assertRaises (AssertionError ):
5537+ C2 [Unpack [U2 ]]
5538+ else :
5539+ with self .assertRaisesRegex (TypeError , "must be used with a tuple type" ):
5540+ C2 [Unpack [U2 ]]
5541+
5542+ C3 = Concatenate [str , T , P ]
5543+ self .assertEqual (C3 [int , [bool ]], (str , int , bool ))
5544+
55325545
55335546class TypeGuardTests (BaseTestCase ):
55345547 def test_basics (self ):
0 commit comments