runtimepy.enum package#

Submodules#

runtimepy.enum.registry module#

A module implementing and enumeration registry.

class runtimepy.enum.registry.EnumRegistry(data: dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]] = None, schemas: SchemaMap = None, dest_attr: str = 'data', verify: bool = True)[source]#

Bases: Registry[RuntimeEnum]

A runtime enumeration registry.

enum(name: str, kind: str | EnumType, items: MutableMapping[str | int, str | int] | MutableMapping[str | bool, str | bool] | MutableMapping[str, bool] | MutableMapping[str, int] = None, primitive: str = 'uint8') RuntimeEnum | None[source]#

Create a new runtime enumeration.

property kind: type[RuntimeEnum]#

Determine what kind of registry this is.

class runtimepy.enum.registry.RuntimeIntEnum(new_class_name, /, names, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: IntEnum

An integer enumeration extension.

classmethod enum_name() str[source]#

Get a name for this enumeration.

classmethod id() int | None[source]#

Override in sub-class to coerce enum id.

classmethod normalize(data: int | str | T) T[source]#

Normalize a value at runtime that is either integer, string or an enum instance.

classmethod primitive() str[source]#

The underlying primitive type for this runtime enumeration.

classmethod register_enum(registry: EnumRegistry, name: str = None) RuntimeEnum[source]#

Register an enumeration to a registry.

classmethod runtime_enum(identifier: int) RuntimeEnum[source]#

Obtain a runtime enumeration from this class.

runtimepy.enum.types module#

A module implementing a type system for runtime enumerations.

class runtimepy.enum.types.EnumType(*values)[source]#

Bases: Enum

An enumeration containing the types of runtime enumerations.

BOOL = 'bool'#
INT = 'int'#
static normalize(val: str | EnumType) EnumType[source]#

Normalize an enumeration type.

valid(val: int | bool) bool[source]#

Determine if a value is valid based on this enumeration.

validate(val: int | bool) None[source]#

Validate a primitive value.

Module contents#

A module implementing a runtime enumeration interface.

class runtimepy.enum.RuntimeEnum(data: dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]] = None, schemas: SchemaMap = None, dest_attr: str = 'data', verify: bool = True)[source]#

Bases: RegistryItem

A class implementing a runtime enumeration.

as_bool(value: str | bool) bool | None[source]#

Attempt to get an enumeration boolean.

as_int(value: str | int) int | None[source]#

Attempt to get an enumeration integer.

as_str(value: str | bool | int) str | None[source]#

Attempt to get an enumeration string.

asdict() dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]][source]#

Obtain a dictionary representing this instance.

property bools: BooleanRegistry#

Get the underlying boolean enumeration.

static data_from_enum(enum: type[IntEnum]) dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]][source]#

Get JSON data from an enumeration class.

static from_enum(enum: type[IntEnum], identifier: int) RuntimeEnum[source]#

Create a runtime enumeration from an enum class.

get_bool(value: str | bool) bool[source]#

Get an enumeration boolean.

get_int(value: str | int | bool) int[source]#

Get an enumeration integer.

get_str(value: str | bool | int) str[source]#

Get an enumeration string.

init(data: dict[str, str | int | float | bool | None | dict[str, str | int | float | bool | None] | list[str | int | float | bool | None]]) None[source]#

Perform implementation-specific initialization.

property ints: NameRegistry#

Get the underlying integer enumeration.

property is_boolean: bool#

Determine if this is a boolean enumeration.

property is_integer: bool#

Determine if this is an integer enumeration.

register_bool(name: str, value: bool) bool[source]#

Register a boolean enumeration.

register_int(name: str) int | None[source]#

Register an integer enumeration.