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:
objectCentral 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
- register(ukft_class)[source]¶
Register a UKFT class in the registry.
- Parameters:
ukft_class (
Type[BaseUKF]) – A BaseUKF subclass to register.- Return type:
- 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.
- 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:
- Returns:
The same class (for use as a decorator).
Example
>>> @register_ukft ... class KnowledgeUKFT(BaseUKF): ... type: str = Field(default="knowledge", frozen=True)