Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/1465.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Update ``Callable`` to be imported from ``collections.abc`` rather than ``typing``.
Reduce the usage of ``typing.Any`` by replacing it with ``object`` where applicable.
3 changes: 1 addition & 2 deletions disnake/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import asyncio
import copy
from abc import ABC
from collections.abc import Mapping, Sequence
from collections.abc import Callable, Mapping, Sequence
from typing import (
TYPE_CHECKING,
Any,
Callable,
Optional,
Protocol,
TypeVar,
Expand Down
16 changes: 8 additions & 8 deletions disnake/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ def to_dict(self) -> ActivityPayload:
"assets": self.assets,
}

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, Game) and other.name == self.name

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self) -> int:
Expand Down Expand Up @@ -620,10 +620,10 @@ def to_dict(self) -> ActivityPayload:
ret["details"] = self.details
return ret

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, Streaming) and other.name == self.name and other.url == self.url

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self) -> int:
Expand Down Expand Up @@ -719,15 +719,15 @@ def name(self) -> str:
""":class:`str`: The activity's name. This will always return "Spotify"."""
return "Spotify"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return (
isinstance(other, Spotify)
and other._session_id == self._session_id
and other._sync_id == self._sync_id
and other.start == self.start
)

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self) -> int:
Expand Down Expand Up @@ -894,14 +894,14 @@ def to_dict(self) -> ActivityPayload:
o["emoji"] = self.emoji.to_dict() # pyright: ignore[reportGeneralTypeIssues]
return o

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return (
isinstance(other, CustomActivity)
and other.name == self.name
and other.emoji == self.emoji
)

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self) -> int:
Expand Down
14 changes: 7 additions & 7 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def __init__(
def __repr__(self) -> str:
return f"<OptionChoice name={self.name!r} value={self.value!r}>"

def __eq__(self, other) -> bool:
def __eq__(self, other: OptionChoice) -> bool:
return (
self.name == other.name
and self.value == other.value
Expand Down Expand Up @@ -335,7 +335,7 @@ def __repr__(self) -> str:
f" min_length={self.min_length!r} max_length={self.max_length!r}>"
)

def __eq__(self, other) -> bool:
def __eq__(self, other: Option) -> bool:
return (
self.name == other.name
and self.description == other.description
Expand Down Expand Up @@ -629,7 +629,7 @@ def __repr__(self) -> str:
def __str__(self) -> str:
return self.name

def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
if not isinstance(other, ApplicationCommand):
return False

Expand Down Expand Up @@ -1088,12 +1088,12 @@ def __init__(

self.options: list[Option] = options or []

def __eq__(self, other) -> bool:
def __eq__(self, other: object) -> bool:
return (
super().__eq__(other)
and self.description == other.description
and self.options == other.options
and self.description_localizations == other.description_localizations
and self.description == other.description # pyright: ignore[reportAttributeAccessIssue]
and self.options == other.options # pyright: ignore[reportAttributeAccessIssue]
and self.description_localizations == other.description_localizations # pyright: ignore[reportAttributeAccessIssue]
)

def add_option(
Expand Down
4 changes: 2 additions & 2 deletions disnake/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import io
import os
from typing import TYPE_CHECKING, Any, Literal, Optional, Union
from typing import TYPE_CHECKING, Literal, Optional, Union

import yarl

Expand Down Expand Up @@ -374,7 +374,7 @@ def __repr__(self) -> str:
shorten = self._url.replace(self.BASE, "")
return f"<Asset url={shorten!r}>"

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, Asset) and self._url == other._url

def __hash__(self) -> int:
Expand Down
7 changes: 3 additions & 4 deletions disnake/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

from __future__ import annotations

from collections.abc import Generator, Mapping
from collections.abc import Callable, Generator, Mapping
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Optional,
TypeVar,
Expand Down Expand Up @@ -292,7 +291,7 @@ class AuditLogDiff:
def __len__(self) -> int:
return len(self.__dict__)

def __iter__(self) -> Generator[tuple[str, Any], None, None]:
def __iter__(self) -> Generator[tuple[str, Any]]:
yield from self.__dict__.items()

def __repr__(self) -> str:
Expand All @@ -303,7 +302,7 @@ def __repr__(self) -> str:

def __getattr__(self, item: str) -> Any: ...

def __setattr__(self, key: str, value: Any) -> Any: ...
def __setattr__(self, key: str, value: object) -> Any: ...


Transformer = Callable[["AuditLogEntry", Any], Any]
Expand Down
3 changes: 2 additions & 1 deletion disnake/backoff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import random
import time
from typing import Callable, Generic, Literal, TypeVar, Union, overload
from collections.abc import Callable
from typing import Generic, Literal, TypeVar, Union, overload

T = TypeVar("T", bool, Literal[True], Literal[False])

Expand Down
5 changes: 2 additions & 3 deletions disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
import asyncio
import datetime
import time
from collections.abc import Iterable, Mapping, Sequence
from collections.abc import Callable, Iterable, Mapping, Sequence
from typing import (
TYPE_CHECKING,
Any,
Callable,
Literal,
NamedTuple,
Optional,
Expand Down Expand Up @@ -4856,7 +4855,7 @@ def flags(self) -> ChannelFlags:

def permissions_for(
self,
obj: Any = None,
obj: object = None,
/,
*,
ignore_timeout: bool = MISSING,
Expand Down
21 changes: 5 additions & 16 deletions disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import sys
import traceback
import types
from collections.abc import Coroutine, Generator, Mapping, Sequence
from collections.abc import Callable, Coroutine, Generator, Mapping, Sequence
from datetime import datetime, timedelta
from errno import ECONNRESET
from typing import (
TYPE_CHECKING,
Any,
Callable,
Literal,
NamedTuple,
Optional,
Expand Down Expand Up @@ -720,13 +719,7 @@ def is_ready(self) -> bool:
"""
return self._ready.is_set()

async def _run_event(
self,
coro: Callable[..., Coroutine[Any, Any, Any]],
event_name: str,
*args: Any,
**kwargs: Any,
) -> None:
async def _run_event(self, coro: CoroFunc, event_name: str, *args: Any, **kwargs: Any) -> None:
try:
await coro(*args, **kwargs)
except asyncio.CancelledError:
Expand All @@ -738,11 +731,7 @@ async def _run_event(
pass

def _schedule_event(
self,
coro: Callable[..., Coroutine[Any, Any, Any]],
event_name: str,
*args: Any,
**kwargs: Any,
self, coro: CoroFunc, event_name: str, *args: Any, **kwargs: Any
) -> asyncio.Task:
wrapped = self._run_event(coro, event_name, *args, **kwargs)
# Schedules the task
Expand Down Expand Up @@ -1531,7 +1520,7 @@ def get_soundboard_sound(self, id: int, /) -> Optional[GuildSoundboardSound]:
"""
return self._connection.get_soundboard_sound(id)

def get_all_channels(self) -> Generator[GuildChannel, None, None]:
def get_all_channels(self) -> Generator[GuildChannel]:
"""A generator that retrieves every :class:`.abc.GuildChannel` the client can 'access'.

This is equivalent to: ::
Expand All @@ -1554,7 +1543,7 @@ def get_all_channels(self) -> Generator[GuildChannel, None, None]:
for guild in self.guilds:
yield from guild.channels

def get_all_members(self) -> Generator[Member, None, None]:
def get_all_members(self) -> Generator[Member]:
"""Returns a generator with every :class:`.Member` the client can see.

This is equivalent to: ::
Expand Down
6 changes: 3 additions & 3 deletions disnake/colour.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import colorsys
import random
from typing import TYPE_CHECKING, Any, Optional, Union
from typing import TYPE_CHECKING, Optional, Union

if TYPE_CHECKING:
from typing_extensions import Self
Expand Down Expand Up @@ -62,10 +62,10 @@ def __init__(self, value: int) -> None:
def _get_byte(self, byte: int) -> int:
return (self.value >> (8 * byte)) & 0xFF

def __eq__(self, other: Any) -> bool:
def __eq__(self, other: object) -> bool:
return isinstance(other, Colour) and self.value == other.value

def __ne__(self, other: Any) -> bool:
def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __str__(self) -> str:
Expand Down
Loading