class documentation

class AutoRegisterMeta(ABCMeta):

Constructor: AutoRegisterMeta(name, bases, attrs, register, ...)

View In Hierarchy

Metaclass for automatically registering modules.

Can be set as a metaclass for abstract base classes. All subclasses of that class will be automatically registered.

Example

>>> REGISTRY = Registry(name="modules")
>>> class Base(
...     metaclass=AutoRegisterMeta,
...     registry=REGISTRY,
...     register=False
... ):
...     pass
>>> class Foo(Base):
...     pass
>>> class Bar(Base, register_name="Baz"):
...     pass
>>> REGISTRY.get("Foo").__name__
'Foo'
>>> Base.REGISTRY.get("Baz").__name__
'Bar'
Method __new__ Automatically register the class.
Instance Variable REGISTRY The internal registry defined on the base class.
def __new__(cls, name: str, bases: tuple[type, ...], attrs: dict[str, type], register: bool = True, register_name: str | None = None, registry: Registry | None = None):

Automatically register the class.

Parameters
clsUndocumented
name:strThe name of the class being created.
bases:tuple[type, ...]The base classes of the class being created.
attrs:dict[str, type]The attributes of the class being created.
register:boolWhether to register this class. Typically should be set to False for abstract base classes.
register_name:str | NoneThe name to register the class under. If None, then use the class name.
registry:Registry | NoneThe registry to use for registration. Will be saved as the REGISTRY attribute of the class if not already set.
Returns
The newly created class.
Raises
ValueErrorIf registration is requested but no registry is available from the class hierarchy or the registry argument.
REGISTRY: Registry =

The internal registry defined on the base class.