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)
| 2580 | |
| 2581 | |
| 2582 | def get_args(tp): |
| 2583 | """Get type arguments with all substitutions performed. |
| 2584 | |
| 2585 | For unions, basic simplifications used by Union constructor are performed. |
| 2586 | |
| 2587 | Examples:: |
| 2588 | |
| 2589 | >>> T = TypeVar('T') |
| 2590 | >>> assert get_args(Dict[str, int]) == (str, int) |
| 2591 | >>> assert get_args(int) == () |
| 2592 | >>> assert get_args(Union[int, Union[T, int], str][int]) == (int, str) |
| 2593 | >>> assert get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) |
| 2594 | >>> assert get_args(Callable[[], T][int]) == ([], int) |
| 2595 | """ |
| 2596 | if isinstance(tp, _AnnotatedAlias): |
| 2597 | return (tp.__origin__,) + tp.__metadata__ |
| 2598 | if isinstance(tp, (_GenericAlias, GenericAlias)): |
| 2599 | res = tp.__args__ |
| 2600 | if _should_unflatten_callable_args(tp, res): |
| 2601 | res = (list(res[:-1]), res[-1]) |
| 2602 | return res |
| 2603 | if isinstance(tp, Union): |
| 2604 | return tp.__args__ |
| 2605 | return () |
| 2606 | |
| 2607 | |
| 2608 | def is_typeddict(tp): |
searching dependent graphs…