Skip to content

Commit

Permalink
+ Constants 支持扩展属性
Browse files Browse the repository at this point in the history
  • Loading branch information
007gzs committed Mar 18, 2024
1 parent 60f245b commit e491dbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cool/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,22 @@ def __init__(self, value):
def __eq__(self, other):
if isinstance(other, ConstantsItemWrapper):
other = other.value
if not isinstance(other, tuple) or not len(self.value) > 0:
return False
return self.value[0] == other[0]
if isinstance(other, (list, tuple)) and other:
other = other[0]
return self.value[0] == other

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

def __hash__(self):
return hash(self.value[0])


class ConstantsItem:
def __init__(self, code, desc):
def __init__(self, code, desc, *ext_args):
self.code = code
self.desc = desc
self.ext_args = ext_args
if hasattr(self, '_value_') and not isinstance(self._value_, ConstantsItemWrapper):
self.__value__ = ConstantsItemWrapper(self._value_)

Expand Down Expand Up @@ -75,10 +79,6 @@ class TestConstants(Constants):
InlineConstants = Enum('InlineConstants', (('a', (1,2)), ('b', (3,4))))
"""

@classmethod
def _missing_(cls, value):
return ConstantsItem(*value)

@classmethod
def get_choices_list(cls):
"""
Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Changelog
================
Version 1.2.13
------------------
+ `Constants` 支持扩展属性

Version 1.2.12
------------------
Expand Down

0 comments on commit e491dbe

Please sign in to comment.