From 76bb212eccc07e1983785aa44e345242b0ab1bdc Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sat, 7 Mar 2026 01:03:48 +0900 Subject: [PATCH 1/4] Correct `_CallableGenericAlias` --- Lib/_collections_abc.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index 23cc6d8faae2da..58175e89c9d8c9 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -459,10 +459,10 @@ def __subclasshook__(cls, C): class _CallableGenericAlias(GenericAlias): - """ Represent `Callable[argtypes, resulttype]`. + """ Represent `Callable[paramtypes, returntype]`. - This sets ``__args__`` to a tuple containing the flattened ``argtypes`` - followed by ``resulttype``. + This sets ``__args__`` to a tuple containing the flattened ``paramtypes`` + followed by ``returntype``. Example: ``Callable[[int, str], float]`` sets ``__args__`` to ``(int, str, float)``. @@ -473,13 +473,13 @@ class _CallableGenericAlias(GenericAlias): def __new__(cls, origin, args): if not (isinstance(args, tuple) and len(args) == 2): raise TypeError( - "Callable must be used as Callable[[arg, ...], result].") - t_args, t_result = args - if isinstance(t_args, (tuple, list)): - args = (*t_args, t_result) - elif not _is_param_expr(t_args): + "Callable must be used as Callable[[paramtype1, ...], returntype].") + t_params, t_return = args + if isinstance(t_params, (tuple, list)): + args = (*t_params, t_return) + elif not _is_param_expr(t_params): raise TypeError(f"Expected a list of types, an ellipsis, " - f"ParamSpec, or Concatenate. Got {t_args}") + f"ParamSpec, or Concatenate. Got {t_params}") return super().__new__(cls, origin, args) def __repr__(self): @@ -508,9 +508,9 @@ def __getitem__(self, item): # args[0] occurs due to things like Z[[int, str, bool]] from PEP 612 if not isinstance(new_args[0], (tuple, list)): - t_result = new_args[-1] - t_args = new_args[:-1] - new_args = (t_args, t_result) + t_params = new_args[:-1] + t_return = new_args[-1] + new_args = (t_params, t_return) return _CallableGenericAlias(Callable, tuple(new_args)) def _is_param_expr(obj): From 8e0dac355265bb9df0a1339a0569219a7c90f3b9 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sat, 7 Mar 2026 01:12:44 +0900 Subject: [PATCH 2/4] Correct `_CallableGenericAlias` class --- Lib/_collections_abc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/_collections_abc.py b/Lib/_collections_abc.py index 58175e89c9d8c9..6d730d259f41c8 100644 --- a/Lib/_collections_abc.py +++ b/Lib/_collections_abc.py @@ -473,7 +473,7 @@ class _CallableGenericAlias(GenericAlias): def __new__(cls, origin, args): if not (isinstance(args, tuple) and len(args) == 2): raise TypeError( - "Callable must be used as Callable[[paramtype1, ...], returntype].") + "Callable must be used as Callable[[paramtype1, paramtype2, ...], returntype].") t_params, t_return = args if isinstance(t_params, (tuple, list)): args = (*t_params, t_return) From 2b6faf1037e134faa96e1a54391f4a1b5c9e0ba3 Mon Sep 17 00:00:00 2001 From: "Kai (Kazuya Ito)" Date: Sat, 7 Mar 2026 01:39:32 +0900 Subject: [PATCH 3/4] Correct `typing.Callable` docstring --- Lib/typing.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Lib/typing.py b/Lib/typing.py index e78fb8b71a996c..fbaf041ef872d8 100644 --- a/Lib/typing.py +++ b/Lib/typing.py @@ -2831,15 +2831,15 @@ class Other(Leaf): # Error reported by type checker Callable.__doc__ = \ """Deprecated alias to collections.abc.Callable. - Callable[[int], str] signifies a function that takes a single + Callable[[int], str] signifies a function that has a single parameter of type int and returns a str. - 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 ParamSpec, - Concatenate or 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, ParamSpec, Concatenate or ellipsis "...". + The return type must be a single type. - There is no syntax to indicate optional or keyword arguments; + There is no syntax to indicate optional or keyword parameters; such function types are rarely used as callback types. """ AbstractSet = _alias(collections.abc.Set, 1, name='AbstractSet') From f324516ef7104cddee55e0b1a0e1de505b6adcb9 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 6 Mar 2026 17:19:12 +0000 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2026-03-06-17-19-11.gh-issue-145602.KC5SLP.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2026-03-06-17-19-11.gh-issue-145602.KC5SLP.rst diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-03-06-17-19-11.gh-issue-145602.KC5SLP.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-03-06-17-19-11.gh-issue-145602.KC5SLP.rst new file mode 100644 index 00000000000000..e94fdc06e7040e --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-03-06-17-19-11.gh-issue-145602.KC5SLP.rst @@ -0,0 +1 @@ +Correct _CallableGenericAlias class and typing.Callable docstring