| Conditions | 2 |
| Total Lines | 15 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from enum import EnumMeta |
||
| 4 | def default_enum_serializer(obj: EnumMeta, |
||
| 5 | *, |
||
| 6 | use_enum_name: bool = True, |
||
| 7 | **_) -> str: |
||
| 8 | """ |
||
| 9 | Serialize the given obj. By default, the name of the enum element is |
||
| 10 | returned. |
||
| 11 | :param obj: an instance of an enum. |
||
| 12 | :param use_enum_name: determines whether the name or the value should be |
||
| 13 | used for serialization. |
||
| 14 | :param _: not used. |
||
| 15 | :return: ``obj`` serialized as a string. |
||
| 16 | """ |
||
| 17 | attr = 'name' if use_enum_name else 'value' |
||
| 18 | return getattr(obj, attr) |
||
| 19 |