Use non-underscore TypeVar in enum code

This commit is contained in:
Rapptz 2021-04-06 07:35:02 -04:00
parent 7e3c5f3faf
commit 72275a73fa

View File

@ -426,14 +426,14 @@ class InteractionType(Enum):
ping = 1 ping = 1
application_command = 2 application_command = 2
_T = TypeVar('_T') T = TypeVar('T')
def create_unknown_value(cls: Type[_T], val: Any) -> _T: def create_unknown_value(cls: Type[T], val: Any) -> T:
value_cls = cls._enum_value_cls_ # type: ignore value_cls = cls._enum_value_cls_ # type: ignore
name = f'unknown_{val}' name = f'unknown_{val}'
return value_cls(name=name, value=val) return value_cls(name=name, value=val)
def try_enum(cls: Type[_T], val: Any) -> _T: def try_enum(cls: Type[T], val: Any) -> T:
"""A function that tries to turn the value into enum ``cls``. """A function that tries to turn the value into enum ``cls``.
If it fails it returns a proxy invalid value instead. If it fails it returns a proxy invalid value instead.