Skip to content

Commit

Permalink
feat: add member_items func && rewrite __str__
Browse files Browse the repository at this point in the history
  • Loading branch information
程浩 committed Jul 5, 2024
1 parent fa574b8 commit 6a986c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion hutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .unittest import TestCaseMixin, disable_elastic_apm, disable_migration, disable_network, fake_time, mock_redis_lock
from .validators import is_chinese_phone, is_int, is_phone, is_singapore_phone, is_telephone, is_uuid

__version__ = "1.0.21"
__version__ = "1.0.22"

__all__ = [
"EmptyContextManager",
Expand Down
10 changes: 10 additions & 0 deletions hutils/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def __new__(cls, value, *args):
obj.obj_values = [value] + list(args)
return obj

def __str__(self):
return self.value

def __repr__(self):
return repr(self.value)

def get_value_at(self, index, default=None):
return list_get(self.obj_values, index, default=default)

Expand All @@ -67,6 +73,10 @@ def chinese_choices(cls) -> List[Tuple]:
def chinese_items(cls) -> Dict:
return dict(cls.chinese_choices())

@classmethod
def member_items(cls) -> Dict:
return cls._value2member_map_

@classmethod
def values(cls) -> Tuple:
return tuple(_.value for _ in cls)
Expand Down

0 comments on commit 6a986c4

Please sign in to comment.