@@ -2876,24 +2876,37 @@ Introspection helpers
2876
2876
if a default value equal to ``None `` was set.
2877
2877
Now the annotation is returned unchanged.
2878
2878
2879
- .. function :: get_args(tp)
2880
2879
.. function :: get_origin(tp)
2881
2880
2882
- Provide basic introspection for generic types and special typing forms.
2883
-
2884
- For a typing object of the form ``X[Y, Z, ...] `` these functions return
2885
- ``X `` and ``(Y, Z, ...) ``. If ``X `` is a generic alias for a builtin or
2881
+ Get the unsubscripted version of a type: for a typing object of the form
2882
+ ``X[Y, Z, ...] `` return ``X ``. If ``X `` is a generic alias for a builtin or
2886
2883
:mod: `collections ` class, it gets normalized to the original class.
2884
+ If ``X `` is an instance of :class: `ParamSpecArgs ` or :class: `ParamSpecKwargs `,
2885
+ return the underlying :class: `ParamSpec `.
2886
+ Return ``None `` for unsupported objects.
2887
+ Examples::
2888
+
2889
+ assert get_origin(str) is None
2890
+ assert get_origin(Dict[str, int]) is dict
2891
+ assert get_origin(Union[int, str]) is Union
2892
+ P = ParamSpec('P')
2893
+ assert get_origin(P.args) is P
2894
+ assert get_origin(P.kwargs) is P
2895
+
2896
+ .. versionadded :: 3.8
2897
+
2898
+ .. function :: get_args(tp)
2899
+
2900
+ Get type arguments with all substitutions performed: for a typing object
2901
+ of the form ``X[Y, Z, ...] `` return ``(Y, Z, ...) ``.
2887
2902
If ``X `` is a union or :class: `Literal ` contained in another
2888
2903
generic type, the order of ``(Y, Z, ...) `` may be different from the order
2889
2904
of the original arguments ``[Y, Z, ...] `` due to type caching.
2890
- For unsupported objects return `` None `` and `` () `` correspondingly .
2905
+ Return `` () `` for unsupported objects .
2891
2906
Examples::
2892
2907
2893
- assert get_origin(Dict[str, int]) is dict
2908
+ assert get_args( int) == ()
2894
2909
assert get_args(Dict[int, str]) == (int, str)
2895
-
2896
- assert get_origin(Union[int, str]) is Union
2897
2910
assert get_args(Union[int, str]) == (int, str)
2898
2911
2899
2912
.. versionadded :: 3.8
0 commit comments