https://github.com/python/cpython/commit/e234662f7fcc1b4ebd71d7bb9a03be83eaeb9dc2
commit: e234662f7fcc1b4ebd71d7bb9a03be83eaeb9dc2
branch: main
author: Rajhans Jadhao <[email protected]>
committer: hugovk <[email protected]>
date: 2026-02-26T15:47:13+02:00
summary:
gh-144190: Clarify get_type_hints() instance behavior in docs (#144831)
files:
M Doc/library/typing.rst
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index a0e396983885d2..ef44701bb251dd 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -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
- or class object.
+ Return a dictionary containing type hints for a function, method, module,
+ class object, or other callable object.
This is often the same as ``obj.__annotations__``, but this function makes
the following changes to the annotations dictionary:
@@ -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.
@@ -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
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]