Skip to content

Commit c6d8747

Browse files
committed
fix 3.10
1 parent be56a0a commit c6d8747

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

typing_extensions/src/typing_extensions.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,16 +2328,25 @@ def add_batch_axis(
23282328
item = typing._type_check(parameters, f'{self._name} accepts only single type')
23292329
return _UnpackAlias(self, (item,))
23302330

2331-
def _collect_type_vars(types):
2331+
# We have to do some monkey patching to deal with the dual nature of
2332+
# Unpack/TypeVarTuple:
2333+
# - We want Unpack to be a kind of TypeVar so it gets accepted in
2334+
# Generic[Unpack[Ts]]
2335+
# - We want it to *not* be treated as a TypeVar for the purposes of
2336+
# counting generic parameters, so that when we subscript a generic,
2337+
# the runtime doesn't try to substitute the Unpack with the subscripted type.
2338+
def _collect_type_vars(types, typevar_types=None):
23322339
"""Collect all type variable contained in types in order of
23332340
first appearance (lexicographic order). For example::
23342341
23352342
_collect_type_vars((T, List[S, T])) == (T, S)
23362343
"""
2344+
if typevar_types is None:
2345+
typevar_types = typing.TypeVar
23372346
tvars = []
23382347
for t in types:
23392348
if (
2340-
isinstance(t, typing.TypeVar)
2349+
isinstance(t, typevar_types)
23412350
and t not in tvars
23422351
and not isinstance(t, _UnpackAlias)
23432352
):

0 commit comments

Comments
 (0)