@@ -93,11 +93,32 @@ class Enum(EnumBase):
9393 def __init_subclass__ (cls , * , comparable : bool = False ) -> None :
9494 super ().__init_subclass__ ()
9595
96- if comparable is True :
97- cls .__lt__ = lambda self , other : isinstance (other , self .__class__ ) and self .value < other .value
98- cls .__gt__ = lambda self , other : isinstance (other , self .__class__ ) and self .value > other .value
99- cls .__le__ = lambda self , other : isinstance (other , self .__class__ ) and self .value <= other .value
100- cls .__ge__ = lambda self , other : isinstance (other , self .__class__ ) and self .value >= other .value
96+ if comparable :
97+
98+ def __lt__ (self : Enum , other : object ) -> bool :
99+ if not isinstance (other , cls ):
100+ return NotImplemented
101+ return self .value < other .value
102+
103+ def __gt__ (self : Enum , other : object ) -> bool :
104+ if not isinstance (other , cls ):
105+ return NotImplemented
106+ return self .value > other .value
107+
108+ def __le__ (self : Enum , other : object ) -> bool :
109+ if not isinstance (other , cls ):
110+ return NotImplemented
111+ return self .value <= other .value
112+
113+ def __ge__ (self : Enum , other : object ) -> bool :
114+ if not isinstance (other , cls ):
115+ return NotImplemented
116+ return self .value >= other .value
117+
118+ cls .__lt__ = __lt__
119+ cls .__gt__ = __gt__
120+ cls .__le__ = __le__
121+ cls .__ge__ = __ge__
101122
102123 @classmethod
103124 def _missing_ (cls , value : Any ) -> Self :
0 commit comments