From 7bad27d215c3958c157cd7a36fe5fdd2f42a8d68 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 5 May 2021 23:23:30 -0400 Subject: [PATCH] Fix SnowflakeList typings --- discord/utils.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/discord/utils.py b/discord/utils.py index 072293124..d4f0a48ca 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -155,6 +155,7 @@ class CachedSlotProperty(Generic[T, T_co]): setattr(instance, self.name, value) return value + class classproperty(Generic[T_co]): def __init__(self, fget: Callable[[Any], T_co]) -> None: self.fget = fget @@ -165,6 +166,7 @@ class classproperty(Generic[T_co]): def __set__(self, instance, value) -> None: raise AttributeError('cannot set attribute') + def cached_slot_property(name: str) -> Callable[[Callable[[T], T_co]], CachedSlotProperty[T, T_co]]: def decorator(func: Callable[[T], T_co]) -> CachedSlotProperty[T, T_co]: return CachedSlotProperty(name, func) @@ -560,7 +562,20 @@ class SnowflakeList(array.array): __slots__ = () - def __new__(cls, data: Sequence[int], *, is_sorted: bool = False): + if TYPE_CHECKING: + + @overload + def __init__(self, data: Iterable[int], *, is_sorted: Literal[False] = False): + ... + + @overload + def __init__(self, data: Sequence[int], *, is_sorted: Literal[True]): + ... + + def __init__(self, data: Union[Sequence[int], Iterable[int]], *, is_sorted: bool = False): + ... + + def __new__(cls, data: Union[Sequence[int], Iterable[int]], *, is_sorted: bool = False): return array.array.__new__(cls, 'Q', data if is_sorted else sorted(data)) # type: ignore def add(self, element: int) -> None: