From 30c4c1e78cd2d221c27ec31cc8eed875fe1528f8 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 18 Mar 2026 12:30:29 -0700 Subject: [PATCH] PEP 827: Wrap the new-style extended callables in a Params argument This Params argument can be thought of as kind of being the bound for ParamSpec, and makes it easy to distinguish when the extended system is being used. --- peps/pep-0827.rst | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/peps/pep-0827.rst b/peps/pep-0827.rst index 92f4834dd90..dc5f747516c 100644 --- a/peps/pep-0827.rst +++ b/peps/pep-0827.rst @@ -389,7 +389,17 @@ We introduce a ``Param`` type that contains all the information about a function type ArgsParam[T] = Param[Literal[None], T, Literal["*"]] type KwargsParam[T] = Param[Literal[None], T, Literal["**"]] -And then, we can represent the type of a function like:: +We also introduce a ``Params`` type that wraps a sequence of ``Param`` +types, serving as the first argument to ``Callable``:: + + class Params[*Ps]: + pass + +The presence of ``Params`` as the first argument to ``Callable`` +distinguishes the extended callable format from the standard format. +``Params`` also serves as a natural bound for ``ParamSpec``. + +We can then represent the type of a function like:: def func( a: int, @@ -406,7 +416,7 @@ And then, we can represent the type of a function like:: as:: Callable[ - [ + Params[ Param[Literal["a"], int, Literal["positional"]], Param[Literal["b"], int], Param[Literal["c"], int, Literal["default"]], @@ -422,7 +432,7 @@ as:: or, using the type abbreviations we provide:: Callable[ - [ + Params[ PosParam[Literal["a"], int], Param[Literal["b"], int], DefaultParam[Literal["c"], int], @@ -1257,6 +1267,10 @@ We present implementations of a selection of them:: ] ] + # KeyOf[T] + # Constructs a union of the names of every member of T. + type KeyOf[T] = Union[*[p.name for p in typing.Iter[typing.Members[T]]]] + # Exclude # Constructs a type by excluding from T all union members assignable to U. type Exclude[T, U] = Union[ @@ -1884,10 +1898,6 @@ Open Issues ``readonly`` had been added as a parameter to ``TypedDict`` we would use that, but it wasn't. -* :ref:`Extended Callables `: Should the extended - argument list be wrapped in a ``typing.Parameters[*Params]`` type (that - will also kind of serve as a bound for ``ParamSpec``)? - * :ref:`Extended Callables `: Currently the qualifiers are short strings for code brevity, but an alternate approach would be to mirror ``inspect.Signature`` more directly, and have an enum