@@ -790,7 +790,7 @@ def __repr__(self):
790
790
return f'ForwardRef({ self .__forward_arg__ !r} { module_repr } )'
791
791
792
792
793
- def _is_unpacked_typevartuple (x ) :
793
+ def _is_unpacked_typevartuple (x : Any ) -> bool :
794
794
return (
795
795
isinstance (x , _UnpackGenericAlias )
796
796
# If x is Unpack[tuple[...]], __parameters__ will be empty.
@@ -799,7 +799,7 @@ def _is_unpacked_typevartuple(x):
799
799
)
800
800
801
801
802
- def _is_typevar_like (x ) :
802
+ def _is_typevar_like (x : Any ) -> bool :
803
803
return isinstance (x , (TypeVar , ParamSpec )) or _is_unpacked_typevartuple (x )
804
804
805
805
@@ -1115,7 +1115,7 @@ def __dir__(self):
1115
1115
+ [attr for attr in dir (self .__origin__ ) if not _is_dunder (attr )]))
1116
1116
1117
1117
1118
- def _is_unpacked_tuple (x ) :
1118
+ def _is_unpacked_tuple (x : Any ) -> bool :
1119
1119
# Is `x` something like `*tuple[int]` or `*tuple[int, ...]`?
1120
1120
if not isinstance (x , _UnpackGenericAlias ):
1121
1121
return False
@@ -1128,7 +1128,7 @@ def _is_unpacked_tuple(x):
1128
1128
return getattr (unpacked_type , '__origin__' , None ) is tuple
1129
1129
1130
1130
1131
- def _is_unpacked_arbitrary_length_tuple (x ) :
1131
+ def _is_unpacked_arbitrary_length_tuple (x : Any ) -> bool :
1132
1132
if not _is_unpacked_tuple (x ):
1133
1133
return False
1134
1134
unpacked_tuple = x .__args__ [0 ]
@@ -1153,13 +1153,26 @@ def _is_unpacked_arbitrary_length_tuple(x):
1153
1153
return False
1154
1154
1155
1155
1156
- def _determine_typevar_substitution (typevars , args ):
1156
+ # Alias for readability in type signatures.
1157
+ _TypeVarOrTypeVarTuple = TypeVar | TypeVarTuple
1158
+
1159
+
1160
+ def _determine_typevar_substitution (
1161
+ typevars : tuple [_TypeVarOrTypeVarTuple , ...],
1162
+ args : tuple [type , ...]
1163
+ ) -> dict [_TypeVarOrTypeVarTuple , type ]:
1157
1164
"""Determines how to assign type arguments to type variables.
1158
1165
1159
1166
Args:
1160
1167
typevars: A tuple of TypeVars and (at most one) TypeVarTuple.
1161
1168
args: A tuple of type arguments to substitute into type variables.
1162
1169
1170
+ Returns:
1171
+ A dictionary mapping type variables to corresponding type arguments.
1172
+
1173
+ Raises:
1174
+ ValueError: A valid substitution cannot be found.
1175
+
1163
1176
Examples:
1164
1177
T1 = TypeVar('T1')
1165
1178
T2 = TypeVar('T2')
0 commit comments