Fix typing issues and improve typing completeness across the library

Co-authored-by: Danny <Rapptz@users.noreply.github.com>
Co-authored-by: Josh <josh.ja.butt@gmail.com>
This commit is contained in:
Stocker
2022-03-13 23:52:10 -04:00
committed by GitHub
parent 603681940f
commit 5aa696ccfa
66 changed files with 1071 additions and 802 deletions

View File

@ -46,8 +46,8 @@ BF = TypeVar('BF', bound='BaseFlags')
class flag_value:
def __init__(self, func: Callable[[Any], int]):
self.flag = func(None)
self.__doc__ = func.__doc__
self.flag: int = func(None)
self.__doc__: Optional[str] = func.__doc__
@overload
def __get__(self, instance: None, owner: Type[BF]) -> Self:
@ -65,7 +65,7 @@ class flag_value:
def __set__(self, instance: BaseFlags, value: bool) -> None:
instance._set_flag(self.flag, value)
def __repr__(self):
def __repr__(self) -> str:
return f'<flag_value flag={self.flag!r}>'
@ -73,8 +73,8 @@ class alias_flag_value(flag_value):
pass
def fill_with_flags(*, inverted: bool = False):
def decorator(cls: Type[BF]):
def fill_with_flags(*, inverted: bool = False) -> Callable[[Type[BF]], Type[BF]]:
def decorator(cls: Type[BF]) -> Type[BF]:
# fmt: off
cls.VALID_FLAGS = {
name: value.flag
@ -116,10 +116,10 @@ class BaseFlags:
self.value = value
return self
def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and self.value == other.value
def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)
def __hash__(self) -> int:
@ -504,8 +504,8 @@ class Intents(BaseFlags):
__slots__ = ()
def __init__(self, **kwargs: bool):
self.value = self.DEFAULT_VALUE
def __init__(self, **kwargs: bool) -> None:
self.value: int = self.DEFAULT_VALUE
for key, value in kwargs.items():
if key not in self.VALID_FLAGS:
raise TypeError(f'{key!r} is not a valid flag name.')
@ -1005,7 +1005,7 @@ class MemberCacheFlags(BaseFlags):
def __init__(self, **kwargs: bool):
bits = max(self.VALID_FLAGS.values()).bit_length()
self.value = (1 << bits) - 1
self.value: int = (1 << bits) - 1
for key, value in kwargs.items():
if key not in self.VALID_FLAGS:
raise TypeError(f'{key!r} is not a valid flag name.')