comment here

This commit is contained in:
ton
2023-03-18 20:03:34 +07:00
commit 4553a0a589
14513 changed files with 2685043 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
from enum import EnumMeta
def default_enum_serializer(obj: EnumMeta,
*,
use_enum_name: bool = True,
**_) -> str:
"""
Serialize the given obj. By default, the name of the enum element is
returned.
:param obj: an instance of an enum.
:param use_enum_name: determines whether the name or the value should be
used for serialization.
:param _: not used.
:return: ``obj`` serialized as a string.
"""
attr = 'name' if use_enum_name else 'value'
return getattr(obj, attr)