Skip to content

Commit 75cd9d0

Browse files
committed
Add some type annotations
1 parent 2604094 commit 75cd9d0

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

Lib/typing.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def __repr__(self):
790790
return f'ForwardRef({self.__forward_arg__!r}{module_repr})'
791791

792792

793-
def _is_unpacked_typevartuple(x):
793+
def _is_unpacked_typevartuple(x: Any) -> bool:
794794
return (
795795
isinstance(x, _UnpackGenericAlias)
796796
# If x is Unpack[tuple[...]], __parameters__ will be empty.
@@ -799,7 +799,7 @@ def _is_unpacked_typevartuple(x):
799799
)
800800

801801

802-
def _is_typevar_like(x):
802+
def _is_typevar_like(x: Any) -> bool:
803803
return isinstance(x, (TypeVar, ParamSpec)) or _is_unpacked_typevartuple(x)
804804

805805

@@ -1115,7 +1115,7 @@ def __dir__(self):
11151115
+ [attr for attr in dir(self.__origin__) if not _is_dunder(attr)]))
11161116

11171117

1118-
def _is_unpacked_tuple(x):
1118+
def _is_unpacked_tuple(x: Any) -> bool:
11191119
# Is `x` something like `*tuple[int]` or `*tuple[int, ...]`?
11201120
if not isinstance(x, _UnpackGenericAlias):
11211121
return False
@@ -1128,7 +1128,7 @@ def _is_unpacked_tuple(x):
11281128
return getattr(unpacked_type, '__origin__', None) is tuple
11291129

11301130

1131-
def _is_unpacked_arbitrary_length_tuple(x):
1131+
def _is_unpacked_arbitrary_length_tuple(x: Any) -> bool:
11321132
if not _is_unpacked_tuple(x):
11331133
return False
11341134
unpacked_tuple = x.__args__[0]
@@ -1153,13 +1153,26 @@ def _is_unpacked_arbitrary_length_tuple(x):
11531153
return False
11541154

11551155

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]:
11571164
"""Determines how to assign type arguments to type variables.
11581165
11591166
Args:
11601167
typevars: A tuple of TypeVars and (at most one) TypeVarTuple.
11611168
args: A tuple of type arguments to substitute into type variables.
11621169
1170+
Returns:
1171+
A dictionary mapping type variables to corresponding type arguments.
1172+
1173+
Raises:
1174+
ValueError: A valid substitution cannot be found.
1175+
11631176
Examples:
11641177
T1 = TypeVar('T1')
11651178
T2 = TypeVar('T2')

0 commit comments

Comments
 (0)