@@ -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
@@ -1980,7 +1981,7 @@ without the dedicated syntax, as documented below.
19801981
19811982.. _typevartuple :
19821983
1983- .. class :: TypeVarTuple(name, *, default=typing.NoDefault)
1984+ .. class :: TypeVarTuple(name, *, bound=None, covariant=False, contravariant=False, infer_variance=False, default=typing.NoDefault)
19841985
19851986 Type variable tuple. A specialized form of :ref: `type variable <typevar >`
19861987 that enables *variadic * generics.
@@ -2090,6 +2091,24 @@ without the dedicated syntax, as documented below.
20902091
20912092 The name of the type variable tuple.
20922093
2094+ .. attribute :: __covariant__
2095+
2096+ Whether the type variable tuple has been explicitly marked as covariant.
2097+
2098+ .. versionadded :: 3.15
2099+
2100+ .. attribute :: __contravariant__
2101+
2102+ Whether the type variable tuple has been explicitly marked as contravariant.
2103+
2104+ .. versionadded :: 3.15
2105+
2106+ .. attribute :: __infer_variance__
2107+
2108+ Whether the type variable tuple's variance should be inferred by type checkers.
2109+
2110+ .. versionadded :: 3.15
2111+
20932112 .. attribute :: __default__
20942113
20952114 The default value of the type variable tuple, or :data: `typing.NoDefault ` if it
@@ -2116,6 +2135,11 @@ without the dedicated syntax, as documented below.
21162135
21172136 .. versionadded :: 3.13
21182137
2138+ Type variable tuples created with ``covariant=True `` or
2139+ ``contravariant=True `` can be used to declare covariant or contravariant
2140+ generic types. The ``bound `` argument is also accepted, similar to
2141+ :class: `TypeVar `, but its actual semantics are yet to be decided.
2142+
21192143 .. versionadded :: 3.11
21202144
21212145 .. versionchanged :: 3.12
@@ -2127,6 +2151,11 @@ without the dedicated syntax, as documented below.
21272151
21282152 Support for default values was added.
21292153
2154+ .. versionchanged :: 3.15
2155+
2156+ Added support for the ``bound ``, ``covariant ``, ``contravariant ``, and
2157+ ``infer_variance `` parameters.
2158+
21302159.. class :: ParamSpec(name, *, bound=None, covariant=False, contravariant=False, default=typing.NoDefault)
21312160
21322161 Parameter specification variable. A specialized version of
@@ -2196,6 +2225,20 @@ without the dedicated syntax, as documented below.
21962225
21972226 The name of the parameter specification.
21982227
2228+ .. attribute :: __covariant__
2229+
2230+ Whether the parameter specification has been explicitly marked as covariant.
2231+
2232+ .. attribute :: __contravariant__
2233+
2234+ Whether the parameter specification has been explicitly marked as contravariant.
2235+
2236+ .. attribute :: __infer_variance__
2237+
2238+ Whether the parameter specification's variance should be inferred by type checkers.
2239+
2240+ .. versionadded :: 3.12
2241+
21992242 .. attribute :: __default__
22002243
22012244 The default value of the parameter specification, or :data: `typing.NoDefault ` if it
@@ -3410,13 +3453,13 @@ Functions and decorators
34103453Introspection helpers
34113454---------------------
34123455
3413- .. 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 )
34143457
34153458 Return a dictionary containing type hints for a function, method, module,
34163459 class object, or other callable object.
34173460
3418- This is often the same as `` obj.__annotations__ `` , but this function makes
3419- 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:
34203463
34213464 * Forward references encoded as string literals or :class: `ForwardRef `
34223465 objects are handled by evaluating them in *globalns *, *localns *, and
@@ -3430,29 +3473,28 @@ Introspection helpers
34303473 annotations from ``C ``'s base classes with those on ``C `` directly. This
34313474 is done by traversing :attr: `C.__mro__ <type.__mro__> ` and iteratively
34323475 combining
3433- ``__annotations__ `` dictionaries. Annotations on classes appearing
3434- earlier in the :term: `method resolution order ` always take precedence over
3435- 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.
34363480 * The function recursively replaces all occurrences of
34373481 ``Annotated[T, ...] ``, ``Required[T] ``, ``NotRequired[T] ``, and ``ReadOnly[T] ``
34383482 with ``T ``, unless *include_extras * is set to ``True `` (see
34393483 :class: `Annotated ` for more information).
34403484
3441- See also :func: `annotationlib.get_annotations `, a lower-level function that
3442- returns annotations more directly.
3443-
34443485 .. caution ::
34453486
34463487 This function may execute arbitrary code contained in annotations.
34473488 See :ref: `annotationlib-security ` for more information.
34483489
34493490 .. note ::
34503491
3451- If any forward references in the annotations of *obj * are not resolvable
3452- or are not valid Python code, this function will raise an exception
3453- such as :exc: `NameError `. For example, this can happen with imported
3454- :ref: `type aliases <type-aliases >` that include forward references,
3455- 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.
34563498
34573499 .. note ::
34583500
@@ -3470,6 +3512,10 @@ Introspection helpers
34703512 if a default value equal to ``None `` was set.
34713513 Now the annotation is returned unchanged.
34723514
3515+ .. versionchanged :: 3.14
3516+ Added the ``format `` parameter. See the documentation on
3517+ :func: `annotationlib.get_annotations ` for more information.
3518+
34733519 .. versionchanged :: 3.14
34743520 Calling :func: `get_type_hints ` on instances is no longer supported.
34753521 Some instances were accepted in earlier versions as an undocumented
0 commit comments