Skip to content

Commit

Permalink
fix 3.10
Browse files Browse the repository at this point in the history
  • Loading branch information
JelleZijlstra committed Dec 1, 2021
1 parent be56a0a commit c6d8747
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions typing_extensions/src/typing_extensions.py
Expand Up @@ -2328,16 +2328,25 @@ def add_batch_axis(
item = typing._type_check(parameters, f'{self._name} accepts only single type')
return _UnpackAlias(self, (item,))

def _collect_type_vars(types):
# We have to do some monkey patching to deal with the dual nature of
# Unpack/TypeVarTuple:
# - We want Unpack to be a kind of TypeVar so it gets accepted in
# Generic[Unpack[Ts]]
# - We want it to *not* be treated as a TypeVar for the purposes of
# counting generic parameters, so that when we subscript a generic,
# the runtime doesn't try to substitute the Unpack with the subscripted type.
def _collect_type_vars(types, typevar_types=None):
"""Collect all type variable contained in types in order of
first appearance (lexicographic order). For example::
_collect_type_vars((T, List[S, T])) == (T, S)
"""
if typevar_types is None:
typevar_types = typing.TypeVar
tvars = []
for t in types:
if (
isinstance(t, typing.TypeVar)
isinstance(t, typevar_types)
and t not in tvars
and not isinstance(t, _UnpackAlias)
):
Expand Down

0 comments on commit c6d8747

Please sign in to comment.