| Total Complexity | 2 |
| Total Lines | 20 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |