improve enum compare function

This commit is contained in:
Fity 2018-08-27 18:01:15 +08:00
parent d728b84e48
commit b7c7096d6b
2 changed files with 10 additions and 5 deletions

View File

@ -12,7 +12,7 @@ from .unmountedtype import UnmountedType
def eq_enum(self, other):
if isinstance(other, self.__class__):
return self is other
return self.value is other
return self.value == other
EnumType = type(PyEnum)

View File

@ -184,14 +184,19 @@ def test_enum_value_as_unmounted_argument():
def test_enum_can_be_compared():
class RGB(Enum):
class MyEnum(Enum):
RED = 1
GREEN = 2
BLUE = 3
BIG_VALUE = 99999999999999
assert RGB.RED == 1
assert RGB.GREEN == 2
assert RGB.BLUE == 3
assert MyEnum.RED == 1
assert MyEnum.GREEN == 2
assert MyEnum.BLUE == 3
assert id(big_value) != id(MyEnum.BIG_VALUE.value)
big_value = 99999999999999
assert MyEnum.BIG_VALUE == big_value
def test_enum_can_be_initialzied():