Get type arguments with all substitutions performed. For unions, basic simplifications used by Union constructor are performed. Examples:: get_args(Dict[str, int]) == (str, int) get_args(int) == () get_args(Union[int, Union[T, int], str][int]) ==
(tp)
| 1032 | return None |
| 1033 | |
| 1034 | def get_args(tp): |
| 1035 | """Get type arguments with all substitutions performed. |
| 1036 | |
| 1037 | For unions, basic simplifications used by Union constructor are performed. |
| 1038 | Examples:: |
| 1039 | get_args(Dict[str, int]) == (str, int) |
| 1040 | get_args(int) == () |
| 1041 | get_args(Union[int, Union[T, int], str][int]) == (int, str) |
| 1042 | get_args(Union[int, Tuple[T, int]][str]) == (int, Tuple[str, int]) |
| 1043 | get_args(Callable[[], T][int]) == ([], int) |
| 1044 | """ |
| 1045 | if isinstance(tp, _AnnotatedAlias): |
| 1046 | return (tp.__origin__,) + tp.__metadata__ |
| 1047 | if isinstance(tp, (typing._GenericAlias, _typing_GenericAlias)): |
| 1048 | if getattr(tp, "_special", False): |
| 1049 | return () |
| 1050 | res = tp.__args__ |
| 1051 | if get_origin(tp) is collections.abc.Callable and res[0] is not Ellipsis: |
| 1052 | res = (list(res[:-1]), res[-1]) |
| 1053 | return res |
| 1054 | return () |
| 1055 | |
| 1056 | |
| 1057 | # 3.10+ |