2828 Sequence ,
2929 TypeVar ,
3030 Union ,
31+ get_args ,
3132 overload ,
3233)
3334
@@ -69,9 +70,6 @@ def resolve_invite(invite: Invite | str) -> str:
6970 return invite
7071
7172
72- __all__ = ("resolve_invite" ,)
73-
74-
7573def get_as_snowflake (data : Any , key : str ) -> int | None :
7674 try :
7775 value = data [key ]
@@ -111,7 +109,7 @@ def parse_ratelimit_header(request: Any, *, use_clock: bool = False) -> float:
111109 return (reset - now ).total_seconds ()
112110
113111
114- def string_width (string : str , * , _IS_ASCII = _IS_ASCII ) -> int :
112+ def string_width (string : str , * , _IS_ASCII : re . Pattern [ str ] = _IS_ASCII ) -> int :
115113 """Returns string's width."""
116114 match = _IS_ASCII .match (string )
117115 if match :
@@ -138,7 +136,7 @@ def resolve_template(code: Template | str) -> str:
138136 :class:`str`
139137 The template code.
140138 """
141- from ..template import Template # noqa: PLC0415 # circular import
139+ from ..template import Template # noqa: PLC0415
142140
143141 if isinstance (code , Template ):
144142 return code .code
@@ -167,10 +165,6 @@ def parse_time(timestamp: None) -> None: ...
167165def parse_time (timestamp : str ) -> datetime .datetime : ...
168166
169167
170- @overload
171- def parse_time (timestamp : str | None ) -> datetime .datetime | None : ...
172-
173-
174168def parse_time (timestamp : str | None ) -> datetime .datetime | None :
175169 """A helper function to convert an ISO 8601 timestamp to a datetime object.
176170
@@ -218,7 +212,6 @@ def warn_deprecated(
218212 stacklevel: :class:`int`
219213 The stacklevel kwarg passed to :func:`warnings.warn`. Defaults to 3.
220214 """
221- warnings .simplefilter ("always" , DeprecationWarning ) # turn off filter
222215 message = f"{ name } is deprecated"
223216 if since :
224217 message += f" since version { since } "
@@ -231,7 +224,6 @@ def warn_deprecated(
231224 message += f" See { reference } for more information."
232225
233226 warnings .warn (message , stacklevel = stacklevel , category = DeprecationWarning )
234- warnings .simplefilter ("default" , DeprecationWarning ) # reset filter
235227
236228
237229def deprecated (
@@ -242,7 +234,7 @@ def deprecated(
242234 stacklevel : int = 3 ,
243235 * ,
244236 use_qualname : bool = True ,
245- ) -> Callable [[Callable [[ P ] , T ]], Callable [[ P ] , T ]]:
237+ ) -> Callable [[Callable [P , T ]], Callable [P , T ]]:
246238 """A decorator implementation of :func:`warn_deprecated`. This will automatically call :func:`warn_deprecated` when
247239 the decorated function is called.
248240
@@ -267,7 +259,7 @@ def deprecated(
267259 will display as ``login``. Defaults to ``True``.
268260 """
269261
270- def actual_decorator (func : Callable [[ P ] , T ]) -> Callable [[ P ] , T ]:
262+ def actual_decorator (func : Callable [P , T ]) -> Callable [P , T ]:
271263 @functools .wraps (func )
272264 def decorated (* args : P .args , ** kwargs : P .kwargs ) -> T :
273265 warn_deprecated (
@@ -289,11 +281,11 @@ def decorated(*args: P.args, **kwargs: P.kwargs) -> T:
289281
290282
291283def flatten_literal_params (parameters : Iterable [Any ]) -> tuple [Any , ...]:
292- params = []
284+ params : list [ Any ] = []
293285 literal_cls = type (Literal [0 ])
294286 for p in parameters :
295287 if isinstance (p , literal_cls ):
296- params .extend (p . __args__ )
288+ params .extend (get_args ( p ) )
297289 else :
298290 params .append (p )
299291 return tuple (params )
@@ -311,7 +303,7 @@ def evaluate_annotation(
311303 cache : dict [str , Any ],
312304 * ,
313305 implicit_str : bool = True ,
314- ):
306+ ) -> Any :
315307 if isinstance (tp , ForwardRef ):
316308 tp = tp .__forward_arg__
317309 # ForwardRefs always evaluate their internals
@@ -329,8 +321,8 @@ def evaluate_annotation(
329321 is_literal = False
330322 args = tp .__args__
331323 if not hasattr (tp , "__origin__" ):
332- if PY_310 and tp .__class__ is types .UnionType : # type: ignore
333- converted = Union [args ] # type: ignore # noqa: UP007
324+ if PY_310 and tp .__class__ is types .UnionType :
325+ converted = Union [args ] # noqa: UP007
334326 return evaluate_annotation (converted , globals , locals , cache )
335327
336328 return tp
@@ -381,7 +373,7 @@ def resolve_annotation(
381373 return evaluate_annotation (annotation , globalns , locals , cache )
382374
383375
384- def delay_task (delay : float , func : Coroutine ):
376+ def delay_task (delay : float , func : Coroutine [ Any , Any , Any ] ):
385377 async def inner_call ():
386378 await asyncio .sleep (delay )
387379 try :
@@ -408,7 +400,7 @@ async def maybe_awaitable(f: Callable[P, T | Awaitable[T]], *args: P.args, **kwa
408400 return value
409401
410402
411- async def sane_wait_for (futures : Iterable [Awaitable [T ]], * , timeout : float ) -> set [asyncio .Future [T ]]:
403+ async def sane_wait_for (futures : Iterable [Awaitable [T ]], * , timeout : float ) -> set [asyncio .Task [T ]]:
412404 ensured = [asyncio .ensure_future (fut ) for fut in futures ]
413405 done , pending = await asyncio .wait (ensured , timeout = timeout , return_when = asyncio .ALL_COMPLETED )
414406
@@ -418,7 +410,7 @@ async def sane_wait_for(futures: Iterable[Awaitable[T]], *, timeout: float) -> s
418410 return done
419411
420412
421- class SnowflakeList (array .array ):
413+ class SnowflakeList (array .array [ int ] ):
422414 """Internal data storage class to efficiently store a list of snowflakes.
423415
424416 This should have the following characteristics:
@@ -437,7 +429,7 @@ class SnowflakeList(array.array):
437429 def __init__ (self , data : Iterable [int ], * , is_sorted : bool = False ): ...
438430
439431 def __new__ (cls , data : Iterable [int ], * , is_sorted : bool = False ):
440- return array . array . __new__ (cls , "Q" , data if is_sorted else sorted (data )) # type: ignore
432+ return super (). __new__ (cls , "Q" , data if is_sorted else sorted (data ))
441433
442434 def add (self , element : int ) -> None :
443435 i = bisect_left (self , element )
@@ -452,22 +444,27 @@ def has(self, element: int) -> bool:
452444 return i != len (self ) and self [i ] == element
453445
454446
455- def copy_doc (original : Callable ) -> Callable [[T ], T ]:
447+ def copy_doc (original : Callable [..., object ] ) -> Callable [[T ], T ]:
456448 def decorator (overridden : T ) -> T :
457449 overridden .__doc__ = original .__doc__
458- overridden .__signature__ = signature (original ) # type: ignore
450+ overridden .__signature__ = signature (original ) # type: ignore[reportAttributeAccessIssue]
459451 return overridden
460452
461453 return decorator
462454
463455
464- class SequenceProxy (collections .abc .Sequence , Generic [T_co ]):
456+ class SequenceProxy (collections .abc .Sequence [ T_co ] , Generic [T_co ]):
465457 """Read-only proxy of a Sequence."""
466458
467459 def __init__ (self , proxied : Sequence [T_co ]):
468460 self .__proxied = proxied
469461
470- def __getitem__ (self , idx : int ) -> T_co :
462+ @overload
463+ def __getitem__ (self , idx : int ) -> T_co : ...
464+ @overload
465+ def __getitem__ (self , idx : slice ) -> Sequence [T_co ]: ...
466+
467+ def __getitem__ (self , idx : int | slice ) -> T_co | Sequence [T_co ]:
471468 return self .__proxied [idx ]
472469
473470 def __len__ (self ) -> int :
@@ -482,7 +479,7 @@ def __iter__(self) -> Iterator[T_co]:
482479 def __reversed__ (self ) -> Iterator [T_co ]:
483480 return reversed (self .__proxied )
484481
485- def index (self , value : Any , * args , ** kwargs ) -> int :
482+ def index (self , value : Any , * args : Any , ** kwargs : Any ) -> int :
486483 return self .__proxied .index (value , * args , ** kwargs )
487484
488485 def count (self , value : Any ) -> int :
@@ -515,10 +512,10 @@ def __get__(self, instance: T | None, owner: type[T]) -> Any:
515512
516513def get_slots (cls : type [Any ]) -> Iterator [str ]:
517514 for mro in reversed (cls .__mro__ ):
518- try :
519- yield from mro .__slots__
520- except AttributeError :
515+ slots = getattr (mro , "__slots__" , None )
516+ if slots is None :
521517 continue
518+ yield from slots
522519
523520
524521def cached_slot_property (
@@ -533,15 +530,15 @@ def decorator(func: Callable[[T], T_co]) -> CachedSlotProperty[T, T_co]:
533530try :
534531 import msgspec
535532
536- def to_json (obj : Any ) -> str : # type: ignore
533+ def to_json (obj : Any ) -> str : # type: ignore[reportUnusedFunction]
537534 return msgspec .json .encode (obj ).decode ("utf-8" )
538535
539- from_json = msgspec .json .decode # type: ignore
536+ from_json = msgspec .json .decode
540537
541538except ModuleNotFoundError :
542539 import json
543540
544- def to_json (obj : Any ) -> str :
541+ def to_json (obj : Any ) -> str : # type: ignore[reportUnusedFunction]
545542 return json .dumps (obj , separators = ("," , ":" ), ensure_ascii = True )
546543
547544 from_json = json .loads
0 commit comments