From 44838e5b2d699a143c1a57902ac0c1d02041765a Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 6 Mar 2026 03:10:41 +0900 Subject: [PATCH 1/5] Correct "Annotating callable objects" --- Doc/library/typing.rst | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 09e9103e1b80d0..d744fdd77b8248 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -209,7 +209,7 @@ Annotating callable objects Functions -- or other :term:`callable` objects -- can be annotated using :class:`collections.abc.Callable` or deprecated :data:`typing.Callable`. -``Callable[[int], str]`` signifies a function that takes a single parameter +``Callable[[int], str]`` signifies a function that has a single parameter of type :class:`int` and returns a :class:`str`. For example: @@ -232,12 +232,11 @@ For example: .. index:: single: ...; ellipsis literal -The subscription syntax must always be used with exactly two values: the -argument list and the return type. The argument list must be a list of types, -a :class:`ParamSpec`, :data:`Concatenate`, or an ellipsis (``...``). The return type must -be a single type. +The type specification `[]` must have two objects, a parameter type list and return type. +The parameter type list must be a list of types, :class:`ParamSpec`, :data:`Concatenate` +or ellipsis (``...``). The return type must be a single type. -If a literal ellipsis ``...`` is given as the argument list, it indicates that +If a literal ellipsis ``...`` is given as the parameter type list, it indicates that a callable with any arbitrary parameter list would be acceptable: .. testcode:: @@ -249,10 +248,9 @@ a callable with any arbitrary parameter list would be acceptable: x = str # OK x = concat # Also OK -``Callable`` cannot express complex signatures such as functions that take a -variadic number of arguments, :ref:`overloaded functions `, or -functions that have keyword-only parameters. However, these signatures can be -expressed by defining a :class:`Protocol` class with a +``Callable`` cannot express complex signatures such as functions that have +keyword-only or var-positional parameters, or :ref:`overloaded functions `. +However, these signatures can be expressed by defining a :class:`Protocol` class with a :meth:`~object.__call__` method: .. testcode:: @@ -281,7 +279,7 @@ parameter types are dependent on each other using :class:`ParamSpec`. Additionally, if that callable adds or removes arguments from other callables, the :data:`Concatenate` operator may be used. They take the form ``Callable[ParamSpecVariable, ReturnType]`` and -``Callable[Concatenate[Arg1Type, Arg2Type, ..., ParamSpecVariable], ReturnType]`` +``Callable[Concatenate[Param1Type, Arg2Type, ..., ParamSpecVariable], ReturnType]`` respectively. .. versionchanged:: 3.10 From 198eb1fa5d766bef778edf983a1f9fba6d6d815b Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 6 Mar 2026 13:27:03 +0900 Subject: [PATCH 2/5] Correct "Annotating callable objects" additional --- Doc/library/typing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index d744fdd77b8248..6a8a3bbab6a710 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -279,7 +279,7 @@ parameter types are dependent on each other using :class:`ParamSpec`. Additionally, if that callable adds or removes arguments from other callables, the :data:`Concatenate` operator may be used. They take the form ``Callable[ParamSpecVariable, ReturnType]`` and -``Callable[Concatenate[Param1Type, Arg2Type, ..., ParamSpecVariable], ReturnType]`` +``Callable[Concatenate[Param1Type, Param2Type, ..., ParamSpecVariable], ReturnType]`` respectively. .. versionchanged:: 3.10 From 6fddb12dee67515cbdbc0d50596733ebb4a02776 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 6 Mar 2026 14:33:34 +0900 Subject: [PATCH 3/5] Update typing.rst --- Doc/library/typing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 6a8a3bbab6a710..574f9152776ea5 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -248,7 +248,7 @@ a callable with any arbitrary parameter list would be acceptable: x = str # OK x = concat # Also OK -``Callable`` cannot express complex signatures such as functions that have +``Callable`` cannot express complex signatures such as functions that have keyword-only or var-positional parameters, or :ref:`overloaded functions `. However, these signatures can be expressed by defining a :class:`Protocol` class with a :meth:`~object.__call__` method: From 35e52b12d211012a771513077f6890e1673530f0 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Fri, 6 Mar 2026 14:51:46 +0900 Subject: [PATCH 4/5] Update typing.rst --- Doc/library/typing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 574f9152776ea5..89e8b1925e26f0 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -232,7 +232,7 @@ For example: .. index:: single: ...; ellipsis literal -The type specification `[]` must have two objects, a parameter type list and return type. +The type specification ``[]`` must have two objects, a parameter type list and return type. The parameter type list must be a list of types, :class:`ParamSpec`, :data:`Concatenate` or ellipsis (``...``). The return type must be a single type. From 6f1851f4aa0c97e2bd38299abd0c7817a15767e0 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sat, 7 Mar 2026 01:10:03 +0900 Subject: [PATCH 5/5] Update typing.rst --- Doc/library/typing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 89e8b1925e26f0..2cc8fdf9797e87 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -279,7 +279,7 @@ parameter types are dependent on each other using :class:`ParamSpec`. Additionally, if that callable adds or removes arguments from other callables, the :data:`Concatenate` operator may be used. They take the form ``Callable[ParamSpecVariable, ReturnType]`` and -``Callable[Concatenate[Param1Type, Param2Type, ..., ParamSpecVariable], ReturnType]`` +``Callable[Concatenate[ParamType1, ParamType2, ..., ParamSpecVariable], ReturnType]`` respectively. .. versionchanged:: 3.10