diff --git a/CHANGELOG.md b/CHANGELOG.md index e31010ddd5aa0fbbd59cd0804a28a8185d3af8cf..2ad95b67e75018ec40f4cc1793c783e3b3447838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ # v2.14.36 * fixed `AlreadySeen` to support non-hashable objects +* improved `ComparableIntEnum` diff --git a/satella/__init__.py b/satella/__init__.py index 242a181ab340c9c0cba02c49cdf5208b9b5f3fcb..041b19ad9bb130f42313c4f85bbb79738f0b5d96 100644 --- a/satella/__init__.py +++ b/satella/__init__.py @@ -1 +1 @@ -__version__ = '2.14.36a1' +__version__ = '2.14.36a3' diff --git a/satella/coding/structures/mixins/enums.py b/satella/coding/structures/mixins/enums.py index 05d05d8ea39577ca6f40fd2a483e2a2ff889a6c7..39b761369abdb96d98e09779b7ceede3d8422684 100644 --- a/satella/coding/structures/mixins/enums.py +++ b/satella/coding/structures/mixins/enums.py @@ -55,7 +55,9 @@ class HashableIntEnum(enum.IntEnum): class ComparableIntEnum(HashableIntEnum): """ 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: @@ -64,24 +66,24 @@ class ComparableIntEnum(HashableIntEnum): def __lt__(self, other: 'ComparableIntEnum') -> bool: if isinstance(other, (int, float)): return self.value < other - return self.value < other.value + return self.value < int(other) def __le__(self, other: 'ComparableIntEnum') -> bool: if isinstance(other, (int, float)): return self.value <= other - return self.value <= other.value + return self.value <= int(other) def __gt__(self, other: 'ComparableIntEnum') -> bool: if isinstance(other, (int, float)): return self.value > other - return self.value > other.value + return self.value > int(other) def __ge__(self, other: 'ComparableIntEnum') -> bool: if isinstance(other, (int, float)): return self.value >= other - return self.value >= other.value + return self.value >= int(other) def __eq__(self, other: 'ComparableIntEnum') -> bool: if isinstance(other, (int, float)): return self.value == other - return self.value == other.value + return self.value == int(other)