Skip to content

bagof.converters.enums

Converters for enumeration types.

Classes

ToEnum

ToEnum(hint: Any = UNSET, compose: bool = False)

Bases: Converter[T, Any]

Converter for Enum (and its subclasses).

A value is resolved first by value (Colour(1)) and then, failing that, by name (Colour["RED"]). Members are returned unchanged.

Note

Only enum.Enum is registered; IntEnum, StrEnum, Flag and the rest dispatch to it as subclasses (and StrEnum does not exist before Python 3.11).

Methods:

__call__
__call__(value: Any) -> T

Convert the value to a member of the enum.