noether.core.schemas.lib

Attributes

T

Classes

Discriminated

Annotated-metadata marker for polymorphic registry config fields.

Functions

resolve_config_class(kind, base_cls)

Resolve a config class from a dotted kind string.

ConfiguredBy(config_class)

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:
  1. If the imported class is already a base_cls subclass, return it directly.

  2. Check for a _config_class attribute (set by @ConfiguredBy).

  3. Inspect __init__ type hints for the first parameter that is a base_cls subclass.

Parameters:
  • kind (str) – fully qualified dotted path (e.g., "noether.training.trainers.WeightedLossTrainer").

  • base_cls (type[T]) – the base config class to resolve against.

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 a BeforeValidator around _discriminated_validator().

  • Serialization — the value is serialized by its runtime class (equivalent to pydantic.SerializeAsAny), so subclass-only fields survive model_dump even when the field is annotated with the base class. Unlike a global model_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
noether.core.schemas.lib.ConfiguredBy(config_class)

Decorator to mark a class as being configured by a specific config class. Usage:

@ConfiguredBy(MyConfig) class MyClass:

Parameters:

config_class (type[pydantic.BaseModel])