Get type arguments with all substitutions performed. For unions, basic simplifications used by Union constructor are performed. Examples:: >>> T = TypeVar('T') >>> assert get_args(Dict[str, int]) == (str, int) >>> assert get_args(int) == () >>> assert get_a
(tp)
| 2511 | |
| 2512 | |
| 2513 | def get_args(tp): |
| 2514 | """Get type arguments with all substitutions performed. |
| 2515 | |
| 2516 | For unions, basic simplifications used by Union constructor are performed. |
| 2517 | |
| 2518 | Examples:: |
| 2519 | |
| 2520 | >>> T = TypeVar('T') |
| 2521 | >>> assert get_args(Dict[str, int]) == (str, int) |
| 2522 | >>> assert get_args(int) == () |
| 2523 | >>> assert get_args(Union[int, Union[T, int], str][int]) == (int, str) |
| 2524 | >>> assert get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) |
| 2525 | >>> assert get_args(Callable[[], T][int]) == ([], int) |
| 2526 | """ |
| 2527 | if isinstance(tp, _AnnotatedAlias): |
| 2528 | return (tp.__origin__,) + tp.__metadata__ |
| 2529 | if isinstance(tp, (_GenericAlias, GenericAlias)): |
| 2530 | res = tp.__args__ |
| 2531 | if _should_unflatten_callable_args(tp, res): |
| 2532 | res = (list(res[:-1]), res[-1]) |
| 2533 | return res |
| 2534 | if isinstance(tp, Union): |
| 2535 | return tp.__args__ |
| 2536 | return () |
| 2537 | |
| 2538 | |
| 2539 | def is_typeddict(tp): |