Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-144190: Clarify get_type_hints() instance behavior in docs#144831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Changes fromall 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
16 changes: 14 additions & 2 deletionsDoc/library/typing.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3353,8 +3353,8 @@ Introspection helpers

.. function:: get_type_hints(obj, globalns=None, localns=None, include_extras=False)

Return a dictionary containing type hints for a function, method, module
orclass object.
Return a dictionary containing type hints for a function, method, module,
class object,orother callable object.

This is often the same as ``obj.__annotations__``, but this function makes
the following changes to the annotations dictionary:
Expand DownExpand Up@@ -3395,6 +3395,13 @@ Introspection helpers
:ref:`type aliases <type-aliases>` that include forward references,
or with names imported under :data:`if TYPE_CHECKING <TYPE_CHECKING>`.

.. note::

Calling :func:`get_type_hints` on an instance is not supported.
To retrieve annotations for an instance, call
:func:`get_type_hints` on the instance's class instead
(for example, ``get_type_hints(type(obj))``).

.. versionchanged:: 3.9
Added ``include_extras`` parameter as part of :pep:`593`.
See the documentation on :data:`Annotated` for more information.
Expand All@@ -3404,6 +3411,11 @@ Introspection helpers
if a default value equal to ``None`` was set.
Now the annotation is returned unchanged.

.. versionchanged:: 3.14
Calling :func:`get_type_hints` on instances is no longer supported.
Some instances were accepted in earlier versions as an undocumented
implementation detail.

.. function:: get_origin(tp)

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

[8]ページ先頭

©2009-2026 Movatter.jp