Skip to content
Snippets Groups Projects
Commit c338f00c authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

improved `ComparableIntEnum`

parent 4621e695
No related branches found
No related tags found
No related merge requests found
# v2.14.36 # v2.14.36
* fixed `AlreadySeen` to support non-hashable objects * fixed `AlreadySeen` to support non-hashable objects
* improved `ComparableIntEnum`
__version__ = '2.14.36a1' __version__ = '2.14.36a3'
...@@ -55,7 +55,9 @@ class HashableIntEnum(enum.IntEnum): ...@@ -55,7 +55,9 @@ class HashableIntEnum(enum.IntEnum):
class ComparableIntEnum(HashableIntEnum): class ComparableIntEnum(HashableIntEnum):
""" """
An enum.IntEnum that implements comparision, stemming from it's values, as well An enum.IntEnum that implements comparision, stemming from it's values, as well
as hashability as hashability.
It it has an int() method, it's fair game as comparison argument for this class.
""" """
def __hash__(self) -> int: def __hash__(self) -> int:
...@@ -64,24 +66,24 @@ class ComparableIntEnum(HashableIntEnum): ...@@ -64,24 +66,24 @@ class ComparableIntEnum(HashableIntEnum):
def __lt__(self, other: 'ComparableIntEnum') -> bool: def __lt__(self, other: 'ComparableIntEnum') -> bool:
if isinstance(other, (int, float)): if isinstance(other, (int, float)):
return self.value < other return self.value < other
return self.value < other.value return self.value < int(other)
def __le__(self, other: 'ComparableIntEnum') -> bool: def __le__(self, other: 'ComparableIntEnum') -> bool:
if isinstance(other, (int, float)): if isinstance(other, (int, float)):
return self.value <= other return self.value <= other
return self.value <= other.value return self.value <= int(other)
def __gt__(self, other: 'ComparableIntEnum') -> bool: def __gt__(self, other: 'ComparableIntEnum') -> bool:
if isinstance(other, (int, float)): if isinstance(other, (int, float)):
return self.value > other return self.value > other
return self.value > other.value return self.value > int(other)
def __ge__(self, other: 'ComparableIntEnum') -> bool: def __ge__(self, other: 'ComparableIntEnum') -> bool:
if isinstance(other, (int, float)): if isinstance(other, (int, float)):
return self.value >= other return self.value >= other
return self.value >= other.value return self.value >= int(other)
def __eq__(self, other: 'ComparableIntEnum') -> bool: def __eq__(self, other: 'ComparableIntEnum') -> bool:
if isinstance(other, (int, float)): if isinstance(other, (int, float)):
return self.value == other return self.value == other
return self.value == other.value return self.value == int(other)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment