Skip to content
Open
Changes from all commits
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
19 changes: 12 additions & 7 deletions Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,7 @@ Functions and decorators
Introspection helpers
---------------------

.. function:: get_type_hints(obj, globalns=None, localns=None, include_extras=False)
.. function:: get_type_hints(obj, globalns=None, localns=None, include_extras=False, *, format=Format.VALUE)

Return a dictionary containing type hints for a function, method, module
or class object.
Expand All @@ -3348,7 +3348,7 @@ Introspection helpers
annotations from ``C``'s base classes with those on ``C`` directly. This
is done by traversing :attr:`C.__mro__ <type.__mro__>` and iteratively
combining
``__annotations__`` dictionaries. Annotations on classes appearing
:term:`annotations <variable annotation>` of each base class. Annotations on classes appearing
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please wrap the line.

earlier in the :term:`method resolution order` always take precedence over
annotations on classes appearing later in the method resolution order.
* The function recursively replaces all occurrences of
Expand All @@ -3366,11 +3366,12 @@ Introspection helpers

.. note::

If any forward references in the annotations of *obj* are not resolvable
or are not valid Python code, this function will raise an exception
such as :exc:`NameError`. For example, this can happen with imported
:ref:`type aliases <type-aliases>` that include forward references,
or with names imported under :data:`if TYPE_CHECKING <TYPE_CHECKING>`.
If :attr:`Format.VALUE <annotationlib.Format.VALUE>` is used and any
forward references in the annotations of *obj* are not resolvable, a
:exc:`NameError` exception is raised. For example, this can happen
with names imported under :data:`if TYPE_CHECKING <TYPE_CHECKING>`.
More generally, any kind of exception can be raised if an annotation
contains invalid Python code.

.. versionchanged:: 3.9
Added ``include_extras`` parameter as part of :pep:`593`.
Expand All @@ -3381,6 +3382,10 @@ Introspection helpers
if a default value equal to ``None`` was set.
Now the annotation is returned unchanged.

.. versionchanged:: 3.14
Added the ``format`` parameter. See the documentation on
:func:`annotationlib.get_annotations` for more information.

.. function:: get_origin(tp)

Get the unsubscripted version of a type: for a typing object of the form
Expand Down
Loading