Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions peps/pep-0827.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"]],
Expand All @@ -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],
Expand Down Expand Up @@ -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<T, U>
# Constructs a type by excluding from T all union members assignable to U.
type Exclude[T, U] = Union[
Expand Down Expand Up @@ -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 <pep827-extended-callables-prereq>`: 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 <pep827-extended-callables-prereq>`: 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
Expand Down
Loading