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
8 changes: 7 additions & 1 deletion peps/pep-0827.rst
Original file line number Diff line number Diff line change
Expand Up @@ -823,13 +823,17 @@ Raise error
Update class
''''''''''''

* ``UpdateClass[*Ps: Member]``: A special form that *updates* an
* ``UpdateClass[Cls, *Ps: Member]``: A special form that *updates* an
existing nominal class with new members (possibly overriding old
ones, or removing them by making them have type ``Never``).

This can only be used in the return type of a type decorator
or as the return type of ``__init_subclass__``.

``Cls`` must be the class to update. For ``__init_subclass__``,
``cls`` ought to have ``type[T]`` and ``T`` should be passed as
``Cls``.

When a class is declared, if one or more of its ancestors have an
``__init_subclass__`` with an ``UpdateClass`` return type, they are
applied in reverse MRO order. If the ``cls`` param is
Expand Down Expand Up @@ -1107,6 +1111,7 @@ based on iterating over all attributes.
def dataclass_ish[T](
cls: type[T],
) -> typing.UpdateClass[
T,
# Add the computed __init__ function
InitFnType[T],
]:
Expand All @@ -1120,6 +1125,7 @@ Or to create a base class (a la Pydantic) that does.
def __init_subclass__[T](
cls: type[T],
) -> typing.UpdateClass[
T,
# Add the computed __init__ function
InitFnType[T],
]:
Expand Down
Loading