File tree 1 file changed +11
-2
lines changed 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -2328,16 +2328,25 @@ def add_batch_axis(
2328
2328
item = typing ._type_check (parameters , f'{ self ._name } accepts only single type' )
2329
2329
return _UnpackAlias (self , (item ,))
2330
2330
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 ):
2332
2339
"""Collect all type variable contained in types in order of
2333
2340
first appearance (lexicographic order). For example::
2334
2341
2335
2342
_collect_type_vars((T, List[S, T])) == (T, S)
2336
2343
"""
2344
+ if typevar_types is None :
2345
+ typevar_types = typing .TypeVar
2337
2346
tvars = []
2338
2347
for t in types :
2339
2348
if (
2340
- isinstance (t , typing . TypeVar )
2349
+ isinstance (t , typevar_types )
2341
2350
and t not in tvars
2342
2351
and not isinstance (t , _UnpackAlias )
2343
2352
):
You can’t perform that action at this time.
0 commit comments