Passed
Pull Request — master (#17)
by Ramon
50s
created

default_enum_deserializer()   A

Complexity

Conditions 2

Size

Total Lines 16
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 16
rs 10
c 0
b 0
f 0
cc 2
nop 4
1
from enum import EnumMeta
2
3
4
def default_enum_deserializer(obj: str,
5
                              cls: EnumMeta,
6
                              use_enum_name: bool = True,
7
                              **kwargs) -> object:
8
    """
9
    Deserialize an enum value to an enum instance. The serialized value must
10
    can be the name of the enum element or the value; dependent on
11
    ``use_enum_name``.
12
    :param obj: the serialized enum.
13
    :param cls: the enum class.
14
    :param use_enum_name: determines whether the name or the value of an enum
15
    element should be used.
16
    :param kwargs: not used.
17
    :return: the corresponding enum element instance.
18
    """
19
    return cls[obj] if use_enum_name else cls(obj)
20