noether.core.schemas.lib¶
Attributes¶
Classes¶
Annotated-metadata marker for polymorphic registry config fields. |
Functions¶
|
Resolve a config class from a dotted kind string. |
|
Decorator to mark a class as being configured by a specific config class. |
Module Contents¶
- noether.core.schemas.lib.T¶
- noether.core.schemas.lib.resolve_config_class[T](kind, base_cls)¶
Resolve a config class from a dotted kind string.
- Resolution order:
If the imported class is already a
base_clssubclass, return it directly.Check for a
_config_classattribute (set by@ConfiguredBy).Inspect
__init__type hints for the first parameter that is abase_clssubclass.
- Parameters:
- Raises:
ValueError – if the config class cannot be determined.
- Return type:
type[T]
- class noether.core.schemas.lib.Discriminated(registry_cls)¶
Annotated-metadata marker for polymorphic registry config fields.
Usage:
field: Annotated[Any, Discriminated(MyComponent)]Contributes two behaviors to the annotated field:
Validation — dicts are instantiated to the concrete config class resolved from their registry key (
kind/type field), like aBeforeValidatoraround_discriminated_validator().Serialization — the value is serialized by its runtime class (equivalent to
pydantic.SerializeAsAny), so subclass-only fields survivemodel_dumpeven when the field is annotated with the base class. Unlike a globalmodel_dump(serialize_as_any=True), this duck-types only the model boundary and still respects field-level serializers nested inside the concrete config (e.g.TorchTensor).
- Parameters:
registry_cls (type[_RegistryBase])
- registry_cls¶