ahvn.ukf.registry module¶

UKF Type Registry for polymorphic deserialization.

This module provides a central registry for all UKF Template (UKFT) classes, enabling polymorphic deserialization based on the type field. The registry follows the naming convention of HEAVEN_CM and HEAVEN_KB.

class ahvn.ukf.registry.UKFTypeRegistry[source]¶

Bases: object

Central registry for UKF Template types.

This registry maps UKF type strings (from the type field) to their corresponding UKFT class implementations. It enables polymorphic deserialization where from_dict and from_ukf can return the appropriate subclass based on the type field.

Example

>>> @register_ukft
... class MyUKFT(BaseUKF):
...     type: str = Field(default="my_type", frozen=True)
>>>
>>> data = {"type": "my_type", "name": "test", ...}
>>> ukf = BaseUKF.from_dict(data)  # Returns MyUKFT instance
>>> isinstance(ukf, MyUKFT)
True
__init__()[source]¶
register(ukft_class)[source]¶

Register a UKFT class in the registry.

Parameters:

ukft_class (Type[BaseUKF]) – A BaseUKF subclass to register.

Return type:

Type[BaseUKF]

Returns:

The same class (for use as a decorator).

Raises:

ValueError – If the class doesn’t have a type field or if the type is already registered.

get(type_name, default=None)[source]¶

Get a UKFT class by its type name.

Parameters:
  • type_name (str) – The type string to look up.

  • default (Type[BaseUKF]) – Default value to return if type not found.

Return type:

Type[BaseUKF]

Returns:

The registered UKFT class for this type, or the default value if not found.

list_types()[source]¶

List all registered type names.

Return type:

list[str]

Returns:

List of registered type strings.

is_registered(type_name)[source]¶

Check if a type is registered.

Parameters:

type_name (str) – The type string to check.

Return type:

bool

Returns:

True if the type is registered, False otherwise.

ahvn.ukf.registry.register_ukft(ukft_class)[source]¶

Decorator to register a UKFT class in the global registry.

This decorator should be applied to all BaseUKF subclasses that represent concrete UKF types. It automatically registers the class in HEAVEN_UR for polymorphic deserialization.

Parameters:

ukft_class (Type[BaseUKF]) – A BaseUKF subclass to register.

Return type:

Type[BaseUKF]

Returns:

The same class (for use as a decorator).

Example

>>> @register_ukft
... class KnowledgeUKFT(BaseUKF):
...     type: str = Field(default="knowledge", frozen=True)