@@ -3346,13 +3346,13 @@ Functions and decorators
33463346Introspection helpers
33473347---------------------
33483348
3349- .. function :: get_type_hints(obj, globalns=None, localns=None, include_extras=False)
3349+ .. function :: get_type_hints(obj, globalns=None, localns=None, include_extras=False, *, format=Format.VALUE )
33503350
33513351 Return a dictionary containing type hints for a function, method, module,
33523352 class object, or other callable object.
33533353
3354- This is often the same as `` obj.__annotations__ `` , but this function makes
3355- the following changes to the annotations dictionary:
3354+ This is often the same as :func: ` annotationlib.get_annotations ` , but this
3355+ function makes the following changes to the annotations dictionary:
33563356
33573357 * Forward references encoded as string literals or :class: `ForwardRef `
33583358 objects are handled by evaluating them in *globalns *, *localns *, and
@@ -3366,29 +3366,28 @@ Introspection helpers
33663366 annotations from ``C ``'s base classes with those on ``C `` directly. This
33673367 is done by traversing :attr: `C.__mro__ <type.__mro__> ` and iteratively
33683368 combining
3369- ``__annotations__ `` dictionaries. Annotations on classes appearing
3370- earlier in the :term: `method resolution order ` always take precedence over
3371- annotations on classes appearing later in the method resolution order.
3369+ :term: `annotations <variable annotation> ` of each base class. Annotations
3370+ on classes appearing earlier in the :term: `method resolution order ` always
3371+ take precedence over annotations on classes appearing later in the method
3372+ resolution order.
33723373 * The function recursively replaces all occurrences of
33733374 ``Annotated[T, ...] ``, ``Required[T] ``, ``NotRequired[T] ``, and ``ReadOnly[T] ``
33743375 with ``T ``, unless *include_extras * is set to ``True `` (see
33753376 :class: `Annotated ` for more information).
33763377
3377- See also :func: `annotationlib.get_annotations `, a lower-level function that
3378- returns annotations more directly.
3379-
33803378 .. caution ::
33813379
33823380 This function may execute arbitrary code contained in annotations.
33833381 See :ref: `annotationlib-security ` for more information.
33843382
33853383 .. note ::
33863384
3387- If any forward references in the annotations of *obj * are not resolvable
3388- or are not valid Python code, this function will raise an exception
3389- such as :exc: `NameError `. For example, this can happen with imported
3390- :ref: `type aliases <type-aliases >` that include forward references,
3391- or with names imported under :data: `if TYPE_CHECKING <TYPE_CHECKING> `.
3385+ If :attr: `Format.VALUE <annotationlib.Format.VALUE> ` is used and any
3386+ forward references in the annotations of *obj * are not resolvable, a
3387+ :exc: `NameError ` exception is raised. For example, this can happen
3388+ with names imported under :data: `if TYPE_CHECKING <TYPE_CHECKING> `.
3389+ More generally, any kind of exception can be raised if an annotation
3390+ contains invalid Python code.
33923391
33933392 .. note ::
33943393
@@ -3406,6 +3405,10 @@ Introspection helpers
34063405 if a default value equal to ``None `` was set.
34073406 Now the annotation is returned unchanged.
34083407
3408+ .. versionchanged :: 3.14
3409+ Added the ``format `` parameter. See the documentation on
3410+ :func: `annotationlib.get_annotations ` for more information.
3411+
34093412 .. versionchanged :: 3.14
34103413 Calling :func: `get_type_hints ` on instances is no longer supported.
34113414 Some instances were accepted in earlier versions as an undocumented
0 commit comments