Skip to content

Commit 7222ea2

Browse files
committed
handle comparable
1 parent 437d9dc commit 7222ea2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

discord/enums.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ class Enum(EnumBase):
8989
not present in any of the members of it.
9090
"""
9191

92+
def __init_subclass__(cls, *, comparable: bool = False) -> None:
93+
super().__init_subclass__()
94+
95+
if comparable is True:
96+
cls.__lt__ = lambda self, other: isinstance(other, self.__class__) and self.value < other.value
97+
cls.__gt__ = lambda self, other: isinstance(other, self.__class__) and self.value > other.value
98+
cls.__le__ = lambda self, other: isinstance(other, self.__class__) and self.value <= other.value
99+
cls.__ge__ = lambda self, other: isinstance(other, self.__class__) and self.value >= other.value
100+
92101
@classmethod
93102
def _missing_(cls, value: Any) -> Self:
94103
name = f"unknown_{value}"

0 commit comments

Comments
 (0)