File tree 1 file changed +11
-2
lines changed
typing_extensions/src_py3 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -2312,16 +2312,25 @@ def add_batch_axis(
2312
2312
item = typing ._type_check (parameters , f'{ self ._name } accepts only single type' )
2313
2313
return _UnpackAlias (self , (item ,))
2314
2314
2315
- def _collect_type_vars (types ):
2315
+ # We have to do some monkey patching to deal with the dual nature of
2316
+ # Unpack/TypeVarTuple:
2317
+ # - We want Unpack to be a kind of TypeVar so it gets accepted in
2318
+ # Generic[Unpack[Ts]]
2319
+ # - We want it to *not* be treated as a TypeVar for the purposes of
2320
+ # counting generic parameters, so that when we subscript a generic,
2321
+ # the runtime doesn't try to substitute the Unpack with the subscripted type.
2322
+ def _collect_type_vars (types , typevar_types = None ):
2316
2323
"""Collect all type variable contained in types in order of
2317
2324
first appearance (lexicographic order). For example::
2318
2325
2319
2326
_collect_type_vars((T, List[S, T])) == (T, S)
2320
2327
"""
2328
+ if typevar_types is None :
2329
+ typevar_types = typing .TypeVar
2321
2330
tvars = []
2322
2331
for t in types :
2323
2332
if (
2324
- isinstance (t , typing . TypeVar )
2333
+ isinstance (t , typevar_types )
2325
2334
and t not in tvars
2326
2335
and not isinstance (t , _UnpackAlias )
2327
2336
):
You can’t perform that action at this time.
0 commit comments