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[源代码]

基类: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.

示例

>>> @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__()[源代码]
register(ukft_class)[源代码]

Register a UKFT class in the registry.

参数:

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

返回类型:

Type[BaseUKF]

返回:

The same class (for use as a decorator).

抛出:

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

get(type_name, default=None)[源代码]

Get a UKFT class by its type name.

参数:
  • type_name (str) -- The type string to look up.

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

返回类型:

Type[BaseUKF]

返回:

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

list_types()[源代码]

List all registered type names.

返回类型:

list[str]

返回:

List of registered type strings.

is_registered(type_name)[源代码]

Check if a type is registered.

参数:

type_name (str) -- The type string to check.

返回类型:

bool

返回:

True if the type is registered, False otherwise.

ahvn.ukf.registry.register_ukft(ukft_class)[源代码]

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.

参数:

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

返回类型:

Type[BaseUKF]

返回:

The same class (for use as a decorator).

示例

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