Special Method Protocols
__prepare__() — class creation protocol
Metaclass hook creating the namespace used while executing the class body. Typically defined with @classmethod. Return a mapping compatible with the metaclass construction step.
Formal Syntax & Structure
python syntaxpython
def __prepare__(mcls, name, bases, **kwargs):Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | str | Class name. |
| bases | tuple | Resolved base classes. |
| **kwargs | dict | Class keywords. |
Return Value
mapping
Class-body namespace.
Working Example
Example Snippetpython
class Meta(type): @classmethod def __prepare__(mcls, name, bases, **kwargs): return {"label": name.lower()}class Report(metaclass=Meta): count=3print(Report.label)