gemd.enumeration.base_enumeration module
Base class for all enumerations.
- class gemd.enumeration.base_enumeration.BaseEnumeration(value)
Bases:
str
,Enum
Enumeration class that can convert between enumerations and associated values.
BaseEnumeration is a powerful support class for string enumerations. It inherits from both str and Enum to enable a class with str capabilities but still a restricted data space. All constructors are case-insensitive on input and a given enumeration can recognize multiple synonyms for input, though only one value will correspond to the value itself. For example:
>>> class Fruits(BaseEnumeration): ... APPLE = "Apple" ... AVOCADO = "Avocado", "Alligator Pear"
will recognize
"apple"
,"APPLE"
and" aPpLe "
as referring to Fruits.APPLE, and"avocado"
and"alligator pear"
as referring to Fruits.AVOCADO. However, since str(Fruits.AVOCADO) is"Avocado"
, Fruits.AVOCADO !="Alligator Pear"
.- classmethod from_str(val: str, *, exception: bool = False) Optional[BaseEnumeration]
Given a string value, return the Enumeration object that matches.
- Parameters
val (str) – The string to match against. Leading and trailing whitespace is ignored. Case is ignored.
exception (bool) – Whether to raise an error if the string doesn’t match anything. Default: False.
- Returns
The matching enumerated element, or None
- Return type
- gemd.enumeration.base_enumeration.migrated_enum(*, old_value: str, new_value: str, deprecated_in: str, removed_in: str) Callable[[Type], Type]
Decorator for registering an enumerated value as migrated to a new symbol.
- Parameters
old_value (str) – A string containing the old symbol name. Used for display only.
new_value (str) – A string containing the new symbol name or the enumeration value. Used to resolve the target value.
deprecated_in (str) – The version of the library the enumerated value was migrated.
removed_in (str) – The version of the library the old enumerated value will be removed in.