File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
typing_extensions/src_py3 Expand file tree Collapse file tree 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(
23122312 item = typing ._type_check (parameters , f'{ self ._name } accepts only single type' )
23132313 return _UnpackAlias (self , (item ,))
23142314
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 ):
23162323 """Collect all type variable contained in types in order of
23172324 first appearance (lexicographic order). For example::
23182325
23192326 _collect_type_vars((T, List[S, T])) == (T, S)
23202327 """
2328+ if typevar_types is None :
2329+ typevar_types = typing .TypeVar
23212330 tvars = []
23222331 for t in types :
23232332 if (
2324- isinstance (t , typing . TypeVar )
2333+ isinstance (t , typevar_types )
23252334 and t not in tvars
23262335 and not isinstance (t , _UnpackAlias )
23272336 ):
You can’t perform that action at this time.
0 commit comments