babylon.engine.dialectics.registry

Type registry for Dialectic subclass deserialization.

Maps type_tag strings to concrete Dialectic subclasses. Used by the repository layer to hydrate the correct Pydantic class from JSONB when loading dialectics from Postgres.

Usage:

from babylon.engine.dialectics.registry import default_registry

cls = default_registry.lookup("CommodityDialectic")
instance = cls(**row_data)

See also

babylon.engine.dialectics.base.Dialectic: Base class with type_tag.

Classes

DialecticRegistry()

Maps type_tag discriminator strings to Dialectic subclasses.

class babylon.engine.dialectics.registry.DialecticRegistry[source]

Bases: object

Maps type_tag discriminator strings to Dialectic subclasses.

Thread-safe for reads after initialization. Registration should happen at import time, not during tick execution.

__init__()[source]
Return type:

None

register(cls)[source]

Register a Dialectic subclass by its type_tag.

Parameters:

cls (type[Dialectic[Any, Any]]) – A concrete Dialectic subclass with type_tag set.

Raises:

ValueError – If a class with the same type_tag is already registered.

Return type:

None

lookup(type_tag)[source]

Look up a Dialectic subclass by type_tag.

Parameters:

type_tag (str) – The discriminator string.

Return type:

type[Dialectic[Any, Any]]

Returns:

The registered Dialectic subclass.

Raises:

KeyError – If type_tag is not registered.

registered_types()[source]

Return all registered type_tag strings.

Return type:

list[str]

Returns:

List of registered type_tag strings.