Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
swapped get_args and get_origin docs, changed "objects" to "types…
…" in `get_origin` doc
  • Loading branch information
chgnrdv committed Apr 30, 2023
commit d53b5952f524f8912a333a1dda92407015ba0899
34 changes: 17 additions & 17 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2881,30 +2881,14 @@ Introspection helpers
if a default value equal to ``None`` was set.
Now the annotation is returned unchanged.

.. function:: get_args(tp)

Get type arguments with all substitutions performed: for a typing object
of the form ``X[Y, Z, ...]`` return ``(Y, Z, ...)``.
If ``X`` is a union or :class:`Literal` contained in another
generic type, the order of ``(Y, Z, ...)`` may be different from the order
of the original arguments ``[Y, Z, ...]`` due to type caching.
Return ``()`` for unsupported objects.
Examples::

assert get_args(int) == ()
assert get_args(Dict[int, str]) == (int, str)
assert get_args(Union[int, str]) == (int, str)

.. versionadded:: 3.8

.. function:: get_origin(tp)

Get the unsubscripted version of a type: for a typing object of the form
``X[Y, Z, ...]`` return ``X``. If ``X`` is a generic alias for a builtin or
:mod:`collections` class, it gets normalized to the original class.
If ``X`` is an instance of :class:`ParamSpecArgs` or :class:`ParamSpecKwargs`,
return the underlying :class:`ParamSpec`.
Return ``None`` for unsupported types.
Return ``None`` for unsupported objects.
Examples::

assert get_origin(str) is None
Expand All @@ -2916,6 +2900,22 @@ Introspection helpers

.. versionadded:: 3.8

.. function:: get_args(tp)

Get type arguments with all substitutions performed: for a typing object
of the form ``X[Y, Z, ...]`` return ``(Y, Z, ...)``.
If ``X`` is a union or :class:`Literal` contained in another
generic type, the order of ``(Y, Z, ...)`` may be different from the order
of the original arguments ``[Y, Z, ...]`` due to type caching.
Return ``()`` for unsupported objects.
Examples::

assert get_args(int) == ()
assert get_args(Dict[int, str]) == (int, str)
assert get_args(Union[int, str]) == (int, str)

.. versionadded:: 3.8

.. function:: is_typeddict(tp)

Check if a type is a :class:`TypedDict`.
Expand Down