From b17a73f2cb8bb2dcdc4063305ac541441250cf87 Mon Sep 17 00:00:00 2001 From: Aki Date: Fri, 7 Oct 2022 23:39:08 +0200 Subject: Ordered StrEnum members to allow sorting Levels --- windy/point_forecast.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/windy/point_forecast.py b/windy/point_forecast.py index 743d85f..54a10c1 100644 --- a/windy/point_forecast.py +++ b/windy/point_forecast.py @@ -19,6 +19,29 @@ def _convert_notation(unit): class _StrEnum(Enum): + def __init__(self, value): + self._index = len(self.__class__.__members__) + + def __lt__(self, other): + if self.__class__ is other.__class__: + return self._index < other._index + return NotImplemented + + def __le__(self, other): + if self.__class__ is other.__class__: + return self._index <= other._index + return NotImplemented + + def __gt__(self, other): + if self.__class__ is other.__class__: + return self._index > other._index + return NotImplemented + + def __ge__(self, other): + if self.__class__ is other.__class__: + return self._index >= other._index + return NotImplemented + def __str__(self): return self.value -- cgit v1.1