@@ -1174,7 +1174,8 @@ These can be used as types in annotations. They all support subscription using
11741174 or transforms parameters of another
11751175 callable. Usage is in the form
11761176 ``Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable] ``. ``Concatenate ``
1177- is currently only valid when used as the first argument to a :ref: `Callable <annotating-callables >`.
1177+ is valid when used in :ref: `Callable <annotating-callables >` type hints
1178+ and when instantiating user-defined generic classes with :class: `ParamSpec ` parameters.
11781179 The last parameter to ``Concatenate `` must be a :class: `ParamSpec ` or
11791180 ellipsis (``... ``).
11801181
@@ -3345,13 +3346,13 @@ Functions and decorators
33453346Introspection helpers
33463347---------------------
33473348
3348- .. 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 )
33493350
33503351 Return a dictionary containing type hints for a function, method, module,
33513352 class object, or other callable object.
33523353
3353- This is often the same as `` obj.__annotations__ `` , but this function makes
3354- 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:
33553356
33563357 * Forward references encoded as string literals or :class: `ForwardRef `
33573358 objects are handled by evaluating them in *globalns *, *localns *, and
@@ -3365,29 +3366,28 @@ Introspection helpers
33653366 annotations from ``C ``'s base classes with those on ``C `` directly. This
33663367 is done by traversing :attr: `C.__mro__ <type.__mro__> ` and iteratively
33673368 combining
3368- ``__annotations__ `` dictionaries. Annotations on classes appearing
3369- earlier in the :term: `method resolution order ` always take precedence over
3370- 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.
33713373 * The function recursively replaces all occurrences of
33723374 ``Annotated[T, ...] ``, ``Required[T] ``, ``NotRequired[T] ``, and ``ReadOnly[T] ``
33733375 with ``T ``, unless *include_extras * is set to ``True `` (see
33743376 :class: `Annotated ` for more information).
33753377
3376- See also :func: `annotationlib.get_annotations `, a lower-level function that
3377- returns annotations more directly.
3378-
33793378 .. caution ::
33803379
33813380 This function may execute arbitrary code contained in annotations.
33823381 See :ref: `annotationlib-security ` for more information.
33833382
33843383 .. note ::
33853384
3386- If any forward references in the annotations of *obj * are not resolvable
3387- or are not valid Python code, this function will raise an exception
3388- such as :exc: `NameError `. For example, this can happen with imported
3389- :ref: `type aliases <type-aliases >` that include forward references,
3390- 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.
33913391
33923392 .. note ::
33933393
@@ -3405,6 +3405,10 @@ Introspection helpers
34053405 if a default value equal to ``None `` was set.
34063406 Now the annotation is returned unchanged.
34073407
3408+ .. versionchanged :: 3.14
3409+ Added the ``format `` parameter. See the documentation on
3410+ :func: `annotationlib.get_annotations ` for more information.
3411+
34083412 .. versionchanged :: 3.14
34093413 Calling :func: `get_type_hints ` on instances is no longer supported.
34103414 Some instances were accepted in earlier versions as an undocumented
0 commit comments