@@ -880,6 +880,11 @@ def test_cannot_be_called(self):
880
880
with self .assertRaises (TypeError ):
881
881
Unpack ()
882
882
883
+ def test_usage_with_kwargs (self ):
884
+ Movie = TypedDict ('Movie' , {'name' : str , 'year' : int })
885
+ def foo (** kwargs : Unpack [Movie ]): ...
886
+ self .assertEqual (repr (foo .__annotations__ ['kwargs' ]),
887
+ f"typing.Unpack[{ __name__ } .Movie]" )
883
888
884
889
class TypeVarTupleTests (BaseTestCase ):
885
890
@@ -1050,14 +1055,14 @@ class G2(Generic[Unpack[Ts]]): pass
1050
1055
1051
1056
self .assertEqual (repr (Ts ), 'Ts' )
1052
1057
1053
- self .assertEqual (repr ((* Ts ,)[0 ]), '*Ts ' )
1054
- self .assertEqual (repr (Unpack [Ts ]), '*Ts ' )
1058
+ self .assertEqual (repr ((* Ts ,)[0 ]), 'typing.Unpack[Ts] ' )
1059
+ self .assertEqual (repr (Unpack [Ts ]), 'typing.Unpack[Ts] ' )
1055
1060
1056
- self .assertEqual (repr (tuple [* Ts ]), 'tuple[*Ts ]' )
1057
- self .assertEqual (repr (Tuple [Unpack [Ts ]]), 'typing.Tuple[*Ts ]' )
1061
+ self .assertEqual (repr (tuple [* Ts ]), 'tuple[typing.Unpack[Ts] ]' )
1062
+ self .assertEqual (repr (Tuple [Unpack [Ts ]]), 'typing.Tuple[typing.Unpack[Ts] ]' )
1058
1063
1059
- self .assertEqual (repr (* tuple [* Ts ]), '*tuple[*Ts ]' )
1060
- self .assertEqual (repr (Unpack [Tuple [Unpack [Ts ]]]), '* typing.Tuple[*Ts ]' )
1064
+ self .assertEqual (repr (* tuple [* Ts ]), '*tuple[typing.Unpack[Ts] ]' )
1065
+ self .assertEqual (repr (Unpack [Tuple [Unpack [Ts ]]]), 'typing.Unpack[typing. Tuple[typing.Unpack[Ts]] ]' )
1061
1066
1062
1067
def test_variadic_class_repr_is_correct (self ):
1063
1068
Ts = TypeVarTuple ('Ts' )
@@ -1074,86 +1079,86 @@ class B(Generic[Unpack[Ts]]): pass
1074
1079
self .assertEndsWith (repr (A [* tuple [int , ...]]),
1075
1080
'A[*tuple[int, ...]]' )
1076
1081
self .assertEndsWith (repr (B [Unpack [Tuple [int , ...]]]),
1077
- 'B[* typing.Tuple[int, ...]]' )
1082
+ 'B[typing.Unpack[typing. Tuple[int, ...] ]]' )
1078
1083
1079
1084
self .assertEndsWith (repr (A [float , * tuple [int , ...]]),
1080
1085
'A[float, *tuple[int, ...]]' )
1081
1086
self .assertEndsWith (repr (A [float , Unpack [Tuple [int , ...]]]),
1082
- 'A[float, * typing.Tuple[int, ...]]' )
1087
+ 'A[float, typing.Unpack[typing. Tuple[int, ...] ]]' )
1083
1088
1084
1089
self .assertEndsWith (repr (A [* tuple [int , ...], str ]),
1085
1090
'A[*tuple[int, ...], str]' )
1086
1091
self .assertEndsWith (repr (B [Unpack [Tuple [int , ...]], str ]),
1087
- 'B[* typing.Tuple[int, ...], str]' )
1092
+ 'B[typing.Unpack[typing. Tuple[int, ...] ], str]' )
1088
1093
1089
1094
self .assertEndsWith (repr (A [float , * tuple [int , ...], str ]),
1090
1095
'A[float, *tuple[int, ...], str]' )
1091
1096
self .assertEndsWith (repr (B [float , Unpack [Tuple [int , ...]], str ]),
1092
- 'B[float, * typing.Tuple[int, ...], str]' )
1097
+ 'B[float, typing.Unpack[typing. Tuple[int, ...] ], str]' )
1093
1098
1094
1099
def test_variadic_class_alias_repr_is_correct (self ):
1095
1100
Ts = TypeVarTuple ('Ts' )
1096
1101
class A (Generic [Unpack [Ts ]]): pass
1097
1102
1098
1103
B = A [* Ts ]
1099
- self .assertEndsWith (repr (B ), 'A[*Ts ]' )
1104
+ self .assertEndsWith (repr (B ), 'A[typing.Unpack[Ts] ]' )
1100
1105
self .assertEndsWith (repr (B [()]), 'A[()]' )
1101
1106
self .assertEndsWith (repr (B [float ]), 'A[float]' )
1102
1107
self .assertEndsWith (repr (B [float , str ]), 'A[float, str]' )
1103
1108
1104
1109
C = A [Unpack [Ts ]]
1105
- self .assertEndsWith (repr (C ), 'A[*Ts ]' )
1110
+ self .assertEndsWith (repr (C ), 'A[typing.Unpack[Ts] ]' )
1106
1111
self .assertEndsWith (repr (C [()]), 'A[()]' )
1107
1112
self .assertEndsWith (repr (C [float ]), 'A[float]' )
1108
1113
self .assertEndsWith (repr (C [float , str ]), 'A[float, str]' )
1109
1114
1110
1115
D = A [* Ts , int ]
1111
- self .assertEndsWith (repr (D ), 'A[*Ts , int]' )
1116
+ self .assertEndsWith (repr (D ), 'A[typing.Unpack[Ts] , int]' )
1112
1117
self .assertEndsWith (repr (D [()]), 'A[int]' )
1113
1118
self .assertEndsWith (repr (D [float ]), 'A[float, int]' )
1114
1119
self .assertEndsWith (repr (D [float , str ]), 'A[float, str, int]' )
1115
1120
1116
1121
E = A [Unpack [Ts ], int ]
1117
- self .assertEndsWith (repr (E ), 'A[*Ts , int]' )
1122
+ self .assertEndsWith (repr (E ), 'A[typing.Unpack[Ts] , int]' )
1118
1123
self .assertEndsWith (repr (E [()]), 'A[int]' )
1119
1124
self .assertEndsWith (repr (E [float ]), 'A[float, int]' )
1120
1125
self .assertEndsWith (repr (E [float , str ]), 'A[float, str, int]' )
1121
1126
1122
1127
F = A [int , * Ts ]
1123
- self .assertEndsWith (repr (F ), 'A[int, *Ts ]' )
1128
+ self .assertEndsWith (repr (F ), 'A[int, typing.Unpack[Ts] ]' )
1124
1129
self .assertEndsWith (repr (F [()]), 'A[int]' )
1125
1130
self .assertEndsWith (repr (F [float ]), 'A[int, float]' )
1126
1131
self .assertEndsWith (repr (F [float , str ]), 'A[int, float, str]' )
1127
1132
1128
1133
G = A [int , Unpack [Ts ]]
1129
- self .assertEndsWith (repr (G ), 'A[int, *Ts ]' )
1134
+ self .assertEndsWith (repr (G ), 'A[int, typing.Unpack[Ts] ]' )
1130
1135
self .assertEndsWith (repr (G [()]), 'A[int]' )
1131
1136
self .assertEndsWith (repr (G [float ]), 'A[int, float]' )
1132
1137
self .assertEndsWith (repr (G [float , str ]), 'A[int, float, str]' )
1133
1138
1134
1139
H = A [int , * Ts , str ]
1135
- self .assertEndsWith (repr (H ), 'A[int, *Ts , str]' )
1140
+ self .assertEndsWith (repr (H ), 'A[int, typing.Unpack[Ts] , str]' )
1136
1141
self .assertEndsWith (repr (H [()]), 'A[int, str]' )
1137
1142
self .assertEndsWith (repr (H [float ]), 'A[int, float, str]' )
1138
1143
self .assertEndsWith (repr (H [float , str ]), 'A[int, float, str, str]' )
1139
1144
1140
1145
I = A [int , Unpack [Ts ], str ]
1141
- self .assertEndsWith (repr (I ), 'A[int, *Ts , str]' )
1146
+ self .assertEndsWith (repr (I ), 'A[int, typing.Unpack[Ts] , str]' )
1142
1147
self .assertEndsWith (repr (I [()]), 'A[int, str]' )
1143
1148
self .assertEndsWith (repr (I [float ]), 'A[int, float, str]' )
1144
1149
self .assertEndsWith (repr (I [float , str ]), 'A[int, float, str, str]' )
1145
1150
1146
1151
J = A [* Ts , * tuple [str , ...]]
1147
- self .assertEndsWith (repr (J ), 'A[*Ts , *tuple[str, ...]]' )
1152
+ self .assertEndsWith (repr (J ), 'A[typing.Unpack[Ts] , *tuple[str, ...]]' )
1148
1153
self .assertEndsWith (repr (J [()]), 'A[*tuple[str, ...]]' )
1149
1154
self .assertEndsWith (repr (J [float ]), 'A[float, *tuple[str, ...]]' )
1150
1155
self .assertEndsWith (repr (J [float , str ]), 'A[float, str, *tuple[str, ...]]' )
1151
1156
1152
1157
K = A [Unpack [Ts ], Unpack [Tuple [str , ...]]]
1153
- self .assertEndsWith (repr (K ), 'A[*Ts, * typing.Tuple[str, ...]]' )
1154
- self .assertEndsWith (repr (K [()]), 'A[* typing.Tuple[str, ...]]' )
1155
- self .assertEndsWith (repr (K [float ]), 'A[float, * typing.Tuple[str, ...]]' )
1156
- self .assertEndsWith (repr (K [float , str ]), 'A[float, str, * typing.Tuple[str, ...]]' )
1158
+ self .assertEndsWith (repr (K ), 'A[typing.Unpack[Ts], typing.Unpack[typing. Tuple[str, ...] ]]' )
1159
+ self .assertEndsWith (repr (K [()]), 'A[typing.Unpack[typing. Tuple[str, ...] ]]' )
1160
+ self .assertEndsWith (repr (K [float ]), 'A[float, typing.Unpack[typing. Tuple[str, ...] ]]' )
1161
+ self .assertEndsWith (repr (K [float , str ]), 'A[float, str, typing.Unpack[typing. Tuple[str, ...] ]]' )
1157
1162
1158
1163
def test_cannot_subclass (self ):
1159
1164
with self .assertRaisesRegex (TypeError , CANNOT_SUBCLASS_TYPE ):
@@ -1171,9 +1176,9 @@ class C(type(Unpack[Ts])): pass
1171
1176
with self .assertRaisesRegex (TypeError ,
1172
1177
r'Cannot subclass typing\.Unpack' ):
1173
1178
class C (Unpack ): pass
1174
- with self .assertRaisesRegex (TypeError , r'Cannot subclass \*Ts ' ):
1179
+ with self .assertRaisesRegex (TypeError , r'Cannot subclass typing.Unpack\[Ts\] ' ):
1175
1180
class C (* Ts ): pass
1176
- with self .assertRaisesRegex (TypeError , r'Cannot subclass \*Ts ' ):
1181
+ with self .assertRaisesRegex (TypeError , r'Cannot subclass typing.Unpack\[Ts\] ' ):
1177
1182
class C (Unpack [Ts ]): pass
1178
1183
1179
1184
def test_variadic_class_args_are_correct (self ):
@@ -4108,13 +4113,13 @@ class TsP(Generic[*Ts, P]):
4108
4113
MyCallable [[int ], bool ]: "MyCallable[[int], bool]" ,
4109
4114
MyCallable [[int , str ], bool ]: "MyCallable[[int, str], bool]" ,
4110
4115
MyCallable [[int , list [int ]], bool ]: "MyCallable[[int, list[int]], bool]" ,
4111
- MyCallable [Concatenate [* Ts , P ], T ]: "MyCallable[typing.Concatenate[*Ts , ~P], ~T]" ,
4116
+ MyCallable [Concatenate [* Ts , P ], T ]: "MyCallable[typing.Concatenate[typing.Unpack[Ts] , ~P], ~T]" ,
4112
4117
4113
4118
DoubleSpec [P2 , P , T ]: "DoubleSpec[~P2, ~P, ~T]" ,
4114
4119
DoubleSpec [[int ], [str ], bool ]: "DoubleSpec[[int], [str], bool]" ,
4115
4120
DoubleSpec [[int , int ], [str , str ], bool ]: "DoubleSpec[[int, int], [str, str], bool]" ,
4116
4121
4117
- TsP [* Ts , P ]: "TsP[*Ts , ~P]" ,
4122
+ TsP [* Ts , P ]: "TsP[typing.Unpack[Ts] , ~P]" ,
4118
4123
TsP [int , str , list [int ], []]: "TsP[int, str, list[int], []]" ,
4119
4124
TsP [int , [str , list [int ]]]: "TsP[int, [str, list[int]]]" ,
4120
4125
0 commit comments