Skip to content

Commit 318f982

Browse files
committed
Change to using aenum in place of stdlib enum, which simplifies code
1 parent 1385352 commit 318f982

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

domdf_python_tools/enums.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,39 +24,39 @@
2424
# MA 02110-1301, USA.
2525
#
2626

27-
from enum import Enum
27+
from aenum import Enum, IntEnum
2828

2929
__all__ = ["IntEnum", "StrEnum"]
3030

3131

32-
class IntEnum(Enum):
33-
"""
34-
An Enum that can be converted into an integer
35-
"""
36-
37-
def __int__(self):
38-
return self.value
39-
40-
def __eq__(self, other):
41-
if int(self) == other:
42-
return True
43-
else:
44-
return super().__eq__(other)
32+
# class IntEnum(Enum):
33+
# """
34+
# An Enum that can be converted into an integer
35+
# """
36+
#
37+
# def __int__(self):
38+
# return self.value
39+
#
40+
# def __eq__(self, other):
41+
# if int(self) == other:
42+
# return True
43+
# else:
44+
# return super().__eq__(other)
4545

4646

47-
class StrEnum(Enum):
47+
class StrEnum(str, Enum):
4848
"""
4949
An Enum that can be converted into a string
5050
"""
5151

5252
def __str__(self):
5353
return self.value
54-
55-
def __repr__(self):
56-
return self.value
57-
58-
def __eq__(self, other):
59-
if str(self) == other:
60-
return True
61-
else:
62-
return super().__eq__(other)
54+
#
55+
# def __repr__(self):
56+
# return self.value
57+
58+
# def __eq__(self, other):
59+
# if str(self) == other:
60+
# return True
61+
# else:
62+
# return super().__eq__(other)

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
pydash>=4.7.4
1+
pydash>=4.7.4
2+
aenum >=2.2.3

tests/test_enums.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def test_str_enum():
2323
assert DramatisPersonae.Message == "a secret message"
2424
assert DramatisPersonae.Alice != "An eavesdropper"
2525
assert str(DramatisPersonae.Craig) == "A password cracker"
26-
assert DramatisPersonae("The sender") == DramatisPersonae.Bob == repr(DramatisPersonae.Bob) == "The sender"
27-
26+
assert DramatisPersonae("The sender") == DramatisPersonae.Bob == "The sender"
27+
assert repr(DramatisPersonae.Bob) == "<DramatisPersonae.Bob: 'The sender'>"
2828

2929
class Numbers(enums.IntEnum):
3030
One = 1
@@ -39,3 +39,4 @@ def test_int_enum():
3939
assert Numbers.Two != 3
4040
assert int(Numbers.Four) == 4
4141
assert Numbers(5) == Numbers.Five == 5
42+
assert isinstance(Numbers(5), int)

0 commit comments

Comments
 (0)