Mixins

Mixins for instantiating enums from keys as well as from values

Usage:

class ExampleEnum(EnumGetterMixin, Enum):
    ITEM1 = 'item 1'
    ITEM2 = 'item 2'

element_from_key = ExampleEnum.from_key('ITEM1')
element_from_value = ExampleEnum.from_value('item 1')
try:
    assert element_from_key == element_from_value
    print("EnumGetterMixin is working.")
except AssertionError:
    print("Example with EnumGetterMixin returned assertion error.")
class reemission.mixins.EnumGetterMixin[source]

A Mixin class providing easier access to enum values via key and value.

This class is a subclass of Enum and is used to instantiate enums from keys as well as from values.

from_value(cls, value)[source]

Returns an Enum object if the value is found in the set of values.

from_key(cls, key)[source]

Returns an Enum object if the key is found in the set of values.

classmethod __init_subclass__(**kwargs) None[source]

Ensure that the child class is iterable.

Parameters:

**kwargs – Arbitrary keyword arguments.

Raises:

TypeError – If the child class is not iterable.

classmethod from_key(key: str) Enum[source]

Return an Enum object if the key is found in the set of keys.

Parameters:

key (str) – The key to look up.

Returns:

The Enum object corresponding to the key.

Return type:

Enum

Raises:

KeyError – If the key is not found.

classmethod from_value(value: str) Enum[source]

Return an Enum object if the value is found in the set of values.

Parameters:

value (str) – The value to look up.

Returns:

The Enum object corresponding to the value.

Return type:

Enum

Raises:

KeyError – If the value is not found.