Skip to content

Commit

Permalink
feat: 默认返回value
Browse files Browse the repository at this point in the history
使Genders.FEMALE等价于 Genders.FEMALE.value
  • Loading branch information
程浩 committed Jan 24, 2024
1 parent a08d16c commit 95f0a40
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion hutils/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@
from hutils.shortcuts import list_get


class TupleEnumMeta(enum.EnumMeta):
"""TupleEnum枚举默认返回value"""

def __getattribute__(cls, name):
attr = super().__getattribute__(name)
if isinstance(attr, enum.Enum):
return attr.value
return attr


class EmptyContextManager(contextlib.ContextDecorator):
"""empty context manager."""

Expand All @@ -24,7 +34,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
return False


class TupleEnum(enum.Enum):
class TupleEnum(enum.Enum, metaclass=TupleEnumMeta):
"""元组枚举类,可以用来存储多层信息。tuple enum for multi-dimension data enum.
Examples::
Expand Down

0 comments on commit 95f0a40

Please sign in to comment.