Get the unsubscripted version of a type. This supports generic types, Callable, Tuple, Union, Literal, Final, ClassVar and Annotated. Return None for unsupported types. Examples:: get_origin(Literal[42]) is Literal get_origin(int) is None get_ori
(tp)
| 1008 | _typing_GenericAlias = typing._GenericAlias |
| 1009 | |
| 1010 | def get_origin(tp): |
| 1011 | """Get the unsubscripted version of a type. |
| 1012 | |
| 1013 | This supports generic types, Callable, Tuple, Union, Literal, Final, ClassVar |
| 1014 | and Annotated. Return None for unsupported types. Examples:: |
| 1015 | |
| 1016 | get_origin(Literal[42]) is Literal |
| 1017 | get_origin(int) is None |
| 1018 | get_origin(ClassVar[int]) is ClassVar |
| 1019 | get_origin(Generic) is Generic |
| 1020 | get_origin(Generic[T]) is Generic |
| 1021 | get_origin(Union[T, int]) is Union |
| 1022 | get_origin(List[Tuple[T, T]][int]) == list |
| 1023 | get_origin(P.args) is P |
| 1024 | """ |
| 1025 | if isinstance(tp, _AnnotatedAlias): |
| 1026 | return Annotated |
| 1027 | if isinstance(tp, (typing._GenericAlias, _typing_GenericAlias, _BaseGenericAlias, |
| 1028 | ParamSpecArgs, ParamSpecKwargs)): |
| 1029 | return tp.__origin__ |
| 1030 | if tp is typing.Generic: |
| 1031 | return typing.Generic |
| 1032 | return None |
| 1033 | |
| 1034 | def get_args(tp): |
| 1035 | """Get type arguments with all substitutions performed. |
no outgoing calls