quchip.utils.registry

Subclass registration and serialization dispatch.

The declaration class BaseThing(Registrable, registry_root=True) makes a registry for that family. Concrete subclasses register under their qualified names. The registry excludes registry roots and abstract classes.

to_dict supplies the type tag. A registry root’s from_dict finds the concrete class and passes it the payload and all extra arguments. Concrete classes implement from_dict or _from_dict_payload. The default payload constructor is cls().

Classes

Registrable()

Mixin that owns a subclass registry and the shared (de)serialization contract.

class quchip.utils.registry.Registrable[source]

Bases: object

Mixin that owns a subclass registry and the shared (de)serialization contract.

to_dict()[source]

Serialize the type tag; subclasses add their own fields.

classmethod from_dict(data, *args, **kwargs)[source]

Reconstruct the object from the output of to_dict().

On the registry root, dispatch to the concrete subclass that data["type"] names, and send *args / **kwargs to it. On a concrete subclass, use _from_dict_payload(). Concrete subclasses that carry a payload override this method directly.

Parameters:
  • data (dict) – Serialized declaration that contains the fully qualified type key.

  • *args (object) – Additional positional arguments for reconstruction, for example coupling endpoints.

  • **kwargs (object) – Keyword arguments for reconstruction that the registered class accepts.