@@ -978,6 +978,38 @@ def foo(**kwargs: Unpack[Movie]): ...
978
978
self .assertEqual (repr (foo .__annotations__ ['kwargs' ]),
979
979
f"typing.Unpack[{ __name__ } .Movie]" )
980
980
981
+ def test_builtin_tuple (self ):
982
+ Ts = TypeVarTuple ("Ts" )
983
+
984
+ class Old (Generic [* Ts ]): ...
985
+ class New [* Ts ]: ...
986
+
987
+ PartOld = Old [int , * Ts ]
988
+ self .assertEqual (PartOld [str ].__args__ , (int , str ))
989
+ self .assertEqual (PartOld [* tuple [str ]].__args__ , (int , str ))
990
+ self .assertEqual (PartOld [* Tuple [str ]].__args__ , (int , str ))
991
+ self .assertEqual (PartOld [Unpack [tuple [str ]]].__args__ , (int , str ))
992
+ self .assertEqual (PartOld [Unpack [Tuple [str ]]].__args__ , (int , str ))
993
+
994
+ PartNew = New [int , * Ts ]
995
+ self .assertEqual (PartNew [str ].__args__ , (int , str ))
996
+ self .assertEqual (PartNew [* tuple [str ]].__args__ , (int , str ))
997
+ self .assertEqual (PartNew [* Tuple [str ]].__args__ , (int , str ))
998
+ self .assertEqual (PartNew [Unpack [tuple [str ]]].__args__ , (int , str ))
999
+ self .assertEqual (PartNew [Unpack [Tuple [str ]]].__args__ , (int , str ))
1000
+
1001
+ def test_unpack_wrong_type (self ):
1002
+ Ts = TypeVarTuple ("Ts" )
1003
+ class Gen [* Ts ]: ...
1004
+ PartGen = Gen [int , * Ts ]
1005
+
1006
+ bad_unpack_param = re .escape ("Unpack[...] must be used with a tuple type" )
1007
+ with self .assertRaisesRegex (TypeError , bad_unpack_param ):
1008
+ PartGen [Unpack [list [int ]]]
1009
+ with self .assertRaisesRegex (TypeError , bad_unpack_param ):
1010
+ PartGen [Unpack [List [int ]]]
1011
+
1012
+
981
1013
class TypeVarTupleTests (BaseTestCase ):
982
1014
983
1015
def assertEndsWith (self , string , tail ):
0 commit comments