diff --git a/pytoolbox/enum.py b/pytoolbox/enum.py index b759e8e9..ac03502d 100644 --- a/pytoolbox/enum.py +++ b/pytoolbox/enum.py @@ -15,11 +15,12 @@ except ImportError: pass else: - import functools - - @functools.total_ordering class OrderedEnum(enum.Enum): - """An enumeration both hash-able and ordered by value.""" + """ + An enumeration both hash-able and ordered by value. + + Reference: https://docs.python.org/3/library/enum.html#orderedenum. + """ def __hash__(self): return hash(self.value) @@ -29,7 +30,27 @@ def __eq__(self, other): return self.value == other.value return NotImplemented + def __ge__(self, other): + if self.__class__ is other.__class__: + return self.value >= other.value + return NotImplemented + + def __gt__(self, other): + if self.__class__ is other.__class__: + return self.value > other.value + return NotImplemented + + def __le__(self, other): + if self.__class__ is other.__class__: + return self.value <= other.value + return NotImplemented + def __lt__(self, other): if self.__class__ is other.__class__: return self.value < other.value return NotImplemented + + def __ne__(self, other): + if self.__class__ is other.__class__: + return self.value != other.value + return NotImplemented