2727
2828import types
2929from enum import Enum as EnumBase
30- from typing import TYPE_CHECKING , Any , Generic , Self , Union
31-
32- from typing_extensions import TypeVar
30+ from typing import Any , Self , TypeVar , Union
3331
3432E = TypeVar ("E" , bound = "Enum" )
35- V = TypeVar ("V" , default = Any )
3633
3734__all__ = (
3835 "Enum" ,
8885)
8986
9087
91- class Enum (EnumBase , Generic [ V ] ):
88+ class Enum (EnumBase ):
9289 """An :class:`enum.Enum` subclass that implements a missing value creation behavior if it is
9390 not present in any of the members of it.
9491 """
9592
96- if TYPE_CHECKING :
97- _value_ : V
98-
99- @property
100- def value (self ) -> V : ...
101-
10293 def __init_subclass__ (cls , * , comparable : bool = False ) -> None :
10394 super ().__init_subclass__ ()
10495
@@ -108,8 +99,9 @@ def __init_subclass__(cls, *, comparable: bool = False) -> None:
10899 cls .__le__ = lambda self , other : isinstance (other , self .__class__ ) and self .value <= other .value
109100 cls .__ge__ = lambda self , other : isinstance (other , self .__class__ ) and self .value >= other .value
110101
102+
111103 @classmethod
112- def _missing_ (cls , value : V ) -> Self :
104+ def _missing_ (cls , value : Any ) -> Self :
113105 name = f"unknown_{ value } "
114106 if name in cls .__members__ :
115107 return cls .__members__ [name ]
0 commit comments