File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,15 @@ class Enum(EnumBase):
8989 not present in any of the members of it.
9090 """
9191
92+ def __init_subclass__ (cls , * , comparable : bool = False ) -> None :
93+ super ().__init_subclass__ ()
94+
95+ if comparable is True :
96+ cls .__lt__ = lambda self , other : isinstance (other , self .__class__ ) and self .value < other .value
97+ cls .__gt__ = lambda self , other : isinstance (other , self .__class__ ) and self .value > other .value
98+ cls .__le__ = lambda self , other : isinstance (other , self .__class__ ) and self .value <= other .value
99+ cls .__ge__ = lambda self , other : isinstance (other , self .__class__ ) and self .value >= other .value
100+
92101 @classmethod
93102 def _missing_ (cls , value : Any ) -> Self :
94103 name = f"unknown_{ value } "
You can’t perform that action at this time.
0 commit comments