File tree Expand file tree Collapse file tree 1 file changed +4
-16
lines changed
Expand file tree Collapse file tree 1 file changed +4
-16
lines changed Original file line number Diff line number Diff line change 2222FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2323DEALINGS IN THE SOFTWARE.
2424"""
25-
2625from __future__ import annotations
2726
2827from enum import Enum as EnumBase
2928import types
3029from typing import Any , Self , TypeVar , Union
3130
31+ E = TypeVar ("E" , bound = "Enum" )
32+
3233__all__ = (
3334 "Enum" ,
3435 "ChannelType" ,
@@ -987,22 +988,9 @@ def __int__(self):
987988 return self .value
988989
989990
990- T = TypeVar ("T" )
991-
992-
993- def create_unknown_value (cls : type [T ], val : Any ) -> T :
994- value_cls = cls ._enum_value_cls_ # type: ignore
995- name = f"unknown_{ val } "
996- return value_cls (name = name , value = val )
997-
998-
999- def try_enum (cls : type [T ], val : Any ) -> T :
991+ def try_enum (cls : type [E ], val : Any ) -> E :
1000992 """A function that tries to turn the value into enum ``cls``.
1001993
1002994 If it fails it returns a proxy invalid value instead.
1003995 """
1004-
1005- try :
1006- return cls ._enum_value_map_ [val ] # type: ignore
1007- except (KeyError , TypeError , AttributeError ):
1008- return create_unknown_value (cls , val )
996+ return cls (val )
You can’t perform that action at this time.
0 commit comments