Special Method Protocols

__init_subclass__() — class creation protocol

Customize newly created subclasses. Implicitly a class method, called on the subclass via the parent hook. Consume your own class keywords and forward the rest with super(); object rejects leftover arguments. The displayed signature is the concrete example contract; constructor or call parameters depend on the class.

Formal Syntax & Structure

python syntaxpython
def __init_subclass__(cls, *, label="default", **kwargs):

Parameters & Attributes

NameTypeDescription
labelstrExample subclass keyword.
**kwargsdictRemaining class keywords.

Return Value

None

Subclass initialization notification.

Working Example

Example Snippetpython
class Plugin:    def __init_subclass__(cls, *, label="default", **kwargs):        super().__init_subclass__(**kwargs)        cls.label=labelclass Reader(Plugin, label="reader"): passprint(Reader.label)
Python Reference