Meaning
The __init__ method of a metaclass, called after a class is created to initialize the class object.
Primary Function
Initializes a newly created class object after its creation by the metaclass's __new__.
Communicative Purpose
Signals that a class is being initialized and allows customization of class creation.
Pattern
def __init__(cls, name, bases, dct):
Core Structure
def __init__(cls, name, bases, dct):
Função primária
Initializes a newly created class object after its creation by the metaclass's __new__.
Propósito comunicativo
Signals that a class is being initialized and allows customization of class creation.
Situações de gatilho
When a class statement is executed with a metaclass, after the class object has been created by __new__.
Contextos
Inside a metaclass definition, during the class creation process.
Padrão
def __init__(cls, name, bases, dct):
Estrutura central
def __init__(cls, name, bases, dct):
Slots de substituição
cls, name, bases, dct
Colocados típicos
- type
- metaclass
- class creation
Substituições comuns
- meta
- name
- bases
- dict
Erros comuns
Using 'self' instead of 'cls'; forgetting to call super().__init__(name, bases, dct); confusing with __new__.
Similar / contraste
__new__ (metaclass __new__) vs __init__; class __init__ vs metaclass __init__.
Interferências
Using instance __init__ signature (self) instead of metaclass signature (cls, name, bases, dct).
Família do chunk
- Metaclass lifecycle
- class creation
Nuance
Receives the class object as its first argument, not an instance.
Efeito pragmático
Allows customization of the class creation process, such as modifying attributes or registering classes.
Dica de memória
metaclass init signature
Upgrade path
Advanced metaclass patterns (e.g., __new__, __prepare__)
Log in to save chunks.