Skip to content

Commit

Permalink
Do not use total_ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
davidfischer-ch committed Feb 5, 2018
1 parent ad91378 commit d42fd74
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions pytoolbox/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

0 comments on commit d42fd74

Please sign in to comment.