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) == () >>> ass
(tp)
| 2471 | |
| 2472 | |
| 2473 | def get_args(tp): |
| 2474 | """Get type arguments with all substitutions performed. |
| 2475 | |
| 2476 | For unions, basic simplifications used by Union constructor are performed. |
| 2477 | |
| 2478 | Examples:: |
| 2479 | |
| 2480 | >>> T = TypeVar('T') |
| 2481 | >>> assert get_args(Dict[str, int]) == (str, int) |
| 2482 | >>> assert get_args(int) == () |
| 2483 | >>> assert get_args(Union[int, Union[T, int], str][int]) == (int, str) |
| 2484 | >>> assert get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) |
| 2485 | >>> assert get_args(Callable[[], T][int]) == ([], int) |
| 2486 | """ |
| 2487 | if isinstance(tp, _AnnotatedAlias): |
| 2488 | return (tp.__origin__,) + tp.__metadata__ |
| 2489 | if isinstance(tp, (_GenericAlias, GenericAlias)): |
| 2490 | res = tp.__args__ |
| 2491 | if _should_unflatten_callable_args(tp, res): |
| 2492 | res = (list(res[:-1]), res[-1]) |
| 2493 | return res |
| 2494 | if isinstance(tp, types.UnionType): |
| 2495 | return tp.__args__ |
| 2496 | return () |
| 2497 | |
| 2498 | |
| 2499 | def is_typeddict(tp): |
no test coverage detected