Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add member_items func && rewrite __str__ #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 7 additions & 0 deletions hutils/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def __new__(cls, value, *args):
obj.obj_values = [value] + list(args)
return obj

def __str__(self):
return self.value

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

Expand All @@ -67,6 +70,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
Loading