Mixins

pydantic_modelable.mixins.ModelableStrEnum

Bases: ModelableEnumMixin, str, _StrEnumImpl

Base class for extensible string enums.

Inherit from this rather than spelling out (ModelableEnumMixin, str, aenum.Enum). At runtime it is exactly that — an empty aenum string enum, extended in place by pydantic_modelable.Modelable.extends_enum — but type checkers see a standard enum.Enum, so subclasses are understood as enums without an aenum-induced # type: ignore.

The schema_title / schema_description subclass keyword arguments provided by ModelableEnumMixin are accepted as usual.

pydantic_modelable.mixins.ModelableEnumMixin

A mixin allowing to define an extensible aenum-based StrEnum.

It must be used to define an enum that can be extended using the class decorator pydantic_modelable.model.Modelable.extend_enum().

Prefer inheriting pydantic_modelable.ModelableStrEnum, which bundles this mixin with the correct enum bases and stays type-checker friendly. Subclass parameters customise the generated json_schema so the extended enum fulfils its role when included in a pydantic-based API:

from pydantic_modelable import ModelableStrEnum

class MyExtensibleEnum(
    ModelableStrEnum,
    schema_title='MyExtensibleEnum',
    schema_description='This is my Enum',
):
    ...

__init_subclass__(schema_title='', schema_description='', **kwargs)

Initialize the ModelableEnumMixin with subclass custom parameters.

Keyword parameters are used to customize the Schema model to be generated:

  • schema_title: The title of the model's generated schema
  • schema_description: The description of the model's generated schema