diff --git a/peps/pep-0827.rst b/peps/pep-0827.rst index eb903187f97..656c0ea7299 100644 --- a/peps/pep-0827.rst +++ b/peps/pep-0827.rst @@ -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 @@ -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], ]: @@ -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], ]: