summaryrefslogtreecommitdiffstats
path: root/Doc/library/typing.rst
diff options
context:
space:
mode:
authorJelle Zijlstra <jelle.zijlstra@gmail.com>2021-04-11 02:57:05 (GMT)
committerGitHub <noreply@github.com>2021-04-11 02:57:05 (GMT)
commit522433601a5c64603dab3d733f41a5db39d237eb (patch)
tree4ed806539350027b86ff9afc1b780288d91d7fb7 /Doc/library/typing.rst
parent750f484752763fe9ac1d6455780aabcb67f25508 (diff)
downloadcpython-522433601a5c64603dab3d733f41a5db39d237eb.zip
cpython-522433601a5c64603dab3d733f41a5db39d237eb.tar.gz
cpython-522433601a5c64603dab3d733f41a5db39d237eb.tar.bz2
bpo-43783: Add ParamSpecArgs/Kwargs (GH-25298)
Diffstat (limited to 'Doc/library/typing.rst')
-rw-r--r--Doc/library/typing.rst24
1 files changed, 22 insertions, 2 deletions
diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst
index 8af57f3..c0c6cdd 100644
--- a/Doc/library/typing.rst
+++ b/Doc/library/typing.rst
@@ -1058,8 +1058,10 @@ These are not used in annotations. They are building blocks for creating generic
components. ``P.args`` represents the tuple of positional parameters in a
given call and should only be used to annotate ``*args``. ``P.kwargs``
represents the mapping of keyword parameters to their values in a given call,
- and should be only be used to annotate ``**kwargs`` or ``**kwds``. Both
- attributes require the annotated parameter to be in scope.
+ and should be only be used to annotate ``**kwargs``. Both
+ attributes require the annotated parameter to be in scope. At runtime,
+ ``P.args`` and ``P.kwargs`` are instances respectively of
+ :class:`ParamSpecArgs` and :class:`ParamSpecKwargs`.
Parameter specification variables created with ``covariant=True`` or
``contravariant=True`` can be used to declare covariant or contravariant
@@ -1078,6 +1080,24 @@ These are not used in annotations. They are building blocks for creating generic
``ParamSpec`` and ``Concatenate``).
* :class:`Callable` and :class:`Concatenate`.
+.. data:: ParamSpecArgs
+.. data:: ParamSpecKwargs
+
+ Arguments and keyword arguments attributes of a :class:`ParamSpec`. The
+ ``P.args`` attribute of a ``ParamSpec`` is an instance of ``ParamSpecArgs``,
+ and ``P.kwargs`` is an instance of ``ParamSpecKwargs``. They are intended
+ for runtime introspection and have no special meaning to static type checkers.
+
+ Calling :func:`get_origin` on either of these objects will return the
+ original ``ParamSpec``::
+
+ P = ParamSpec("P")
+ get_origin(P.args) # returns P
+ get_origin(P.kwargs) # returns P
+
+ .. versionadded:: 3.10
+
+
.. data:: AnyStr
``AnyStr`` is a type variable defined as