@@ -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
@@ -3452,13 +3453,13 @@ Functions and decorators
34523453Introspection helpers
34533454---------------------
34543455
3455- .. function :: get_type_hints(obj, globalns=None, localns=None, include_extras=False)
3456+ .. function :: get_type_hints(obj, globalns=None, localns=None, include_extras=False, *, format=Format.VALUE )
34563457
34573458 Return a dictionary containing type hints for a function, method, module,
34583459 class object, or other callable object.
34593460
3460- This is often the same as `` obj.__annotations__ `` , but this function makes
3461- the following changes to the annotations dictionary:
3461+ This is often the same as :func: ` annotationlib.get_annotations ` , but this
3462+ function makes the following changes to the annotations dictionary:
34623463
34633464 * Forward references encoded as string literals or :class: `ForwardRef `
34643465 objects are handled by evaluating them in *globalns *, *localns *, and
@@ -3472,29 +3473,28 @@ Introspection helpers
34723473 annotations from ``C ``'s base classes with those on ``C `` directly. This
34733474 is done by traversing :attr: `C.__mro__ <type.__mro__> ` and iteratively
34743475 combining
3475- ``__annotations__ `` dictionaries. Annotations on classes appearing
3476- earlier in the :term: `method resolution order ` always take precedence over
3477- annotations on classes appearing later in the method resolution order.
3476+ :term: `annotations <variable annotation> ` of each base class. Annotations
3477+ on classes appearing earlier in the :term: `method resolution order ` always
3478+ take precedence over annotations on classes appearing later in the method
3479+ resolution order.
34783480 * The function recursively replaces all occurrences of
34793481 ``Annotated[T, ...] ``, ``Required[T] ``, ``NotRequired[T] ``, and ``ReadOnly[T] ``
34803482 with ``T ``, unless *include_extras * is set to ``True `` (see
34813483 :class: `Annotated ` for more information).
34823484
3483- See also :func: `annotationlib.get_annotations `, a lower-level function that
3484- returns annotations more directly.
3485-
34863485 .. caution ::
34873486
34883487 This function may execute arbitrary code contained in annotations.
34893488 See :ref: `annotationlib-security ` for more information.
34903489
34913490 .. note ::
34923491
3493- If any forward references in the annotations of *obj * are not resolvable
3494- or are not valid Python code, this function will raise an exception
3495- such as :exc: `NameError `. For example, this can happen with imported
3496- :ref: `type aliases <type-aliases >` that include forward references,
3497- or with names imported under :data: `if TYPE_CHECKING <TYPE_CHECKING> `.
3492+ If :attr: `Format.VALUE <annotationlib.Format.VALUE> ` is used and any
3493+ forward references in the annotations of *obj * are not resolvable, a
3494+ :exc: `NameError ` exception is raised. For example, this can happen
3495+ with names imported under :data: `if TYPE_CHECKING <TYPE_CHECKING> `.
3496+ More generally, any kind of exception can be raised if an annotation
3497+ contains invalid Python code.
34983498
34993499 .. note ::
35003500
@@ -3512,6 +3512,10 @@ Introspection helpers
35123512 if a default value equal to ``None `` was set.
35133513 Now the annotation is returned unchanged.
35143514
3515+ .. versionchanged :: 3.14
3516+ Added the ``format `` parameter. See the documentation on
3517+ :func: `annotationlib.get_annotations ` for more information.
3518+
35153519 .. versionchanged :: 3.14
35163520 Calling :func: `get_type_hints ` on instances is no longer supported.
35173521 Some instances were accepted in earlier versions as an undocumented
0 commit comments