@@ -421,6 +421,17 @@ def inner(*args, **kwds):
421
421
return decorator
422
422
423
423
424
+ def _rebuild_generic_alias (alias : GenericAlias , args : tuple [object , ...]) -> GenericAlias :
425
+ is_unpacked = alias .__unpacked__
426
+ if _should_unflatten_callable_args (alias , args ):
427
+ t = alias .__origin__ [(args [:- 1 ], args [- 1 ])]
428
+ else :
429
+ t = alias .__origin__ [args ]
430
+ if is_unpacked :
431
+ t = Unpack [t ]
432
+ return t
433
+
434
+
424
435
def _deprecation_warning_for_no_type_params_passed (funcname : str ) -> None :
425
436
import warnings
426
437
@@ -468,25 +479,20 @@ def _eval_type(t, globalns, localns, type_params=_sentinel, *, recursive_guard=f
468
479
_make_forward_ref (arg ) if isinstance (arg , str ) else arg
469
480
for arg in t .__args__
470
481
)
471
- is_unpacked = t .__unpacked__
472
- if _should_unflatten_callable_args (t , args ):
473
- t = t .__origin__ [(args [:- 1 ], args [- 1 ])]
474
- else :
475
- t = t .__origin__ [args ]
476
- if is_unpacked :
477
- t = Unpack [t ]
482
+ else :
483
+ args = t .__args__
478
484
479
485
ev_args = tuple (
480
486
_eval_type (
481
487
a , globalns , localns , type_params , recursive_guard = recursive_guard ,
482
488
format = format , owner = owner ,
483
489
)
484
- for a in t . __args__
490
+ for a in args
485
491
)
486
492
if ev_args == t .__args__ :
487
493
return t
488
494
if isinstance (t , GenericAlias ):
489
- return GenericAlias ( t . __origin__ , ev_args )
495
+ return _rebuild_generic_alias ( t , ev_args )
490
496
if isinstance (t , Union ):
491
497
return functools .reduce (operator .or_ , ev_args )
492
498
else :
@@ -2400,7 +2406,7 @@ def _strip_annotations(t):
2400
2406
stripped_args = tuple (_strip_annotations (a ) for a in t .__args__ )
2401
2407
if stripped_args == t .__args__ :
2402
2408
return t
2403
- return GenericAlias ( t . __origin__ , stripped_args )
2409
+ return _rebuild_generic_alias ( t , stripped_args )
2404
2410
if isinstance (t , Union ):
2405
2411
stripped_args = tuple (_strip_annotations (a ) for a in t .__args__ )
2406
2412
if stripped_args == t .__args__ :
0 commit comments