Skip to content

Commit

Permalink
[refactor,feat]: use float() directly, also add __le__ and __ge__ hel…
Browse files Browse the repository at this point in the history
…per implementations
  • Loading branch information
null8626 committed Oct 16, 2024
1 parent 0d6085f commit fe872c3
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions python_weather/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ class IndexedEnum(Enum):
"""The index value."""

def __lt__(self, other: Union['IndexedEnum', int, float]) -> bool:
return self.index < getattr(other, 'index', other)
return float(self.index) < float(other)

def __le__(self, other: Union['IndexedEnum', int, float]) -> bool:
return float(self.index) <= float(other)

def __eq__(self, other: Union['IndexedEnum', int, float]) -> bool:
return self.index == getattr(other, 'index', other)
return float(self.index) == float(other)

def __gt__(self, other: Union['IndexedEnum', int, float]) -> bool:
return self.index > getattr(other, 'index', other)
return float(self.index) > float(other)

def __ge__(self, other: Union['IndexedEnum', int, float]) -> bool:
return float(self.index) >= float(other)

def __hash__(self) -> int:
return self.index
Expand Down Expand Up @@ -154,7 +160,7 @@ def _new(value: str, degrees: float) -> 'WindDirection':
return enum

def __contains__(self, other: Union['WindDirection', float, int]) -> bool:
other = getattr(other, 'degrees', other)
other = float(other)

if self is self.NORTH:
return other > 348.75 or other <= 11.25
Expand Down

0 comments on commit fe872c3

Please sign in to comment.