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

jsons.deserializers.default_enum   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 7
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A default_enum_deserializer() 0 16 2
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