Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(typing): complete unparametrized generics #1199

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def __init__(
type: Optional[Union[OptionType, int]] = None,
required: bool = False,
choices: Optional[Choices] = None,
options: Optional[list] = None,
options: Optional[List[Option]] = None,
channel_types: Optional[List[ChannelType]] = None,
autocomplete: bool = False,
min_value: Optional[float] = None,
Expand Down Expand Up @@ -392,7 +392,7 @@ def add_option(
type: Optional[OptionType] = None,
required: bool = False,
choices: Optional[Choices] = None,
options: Optional[list] = None,
options: Optional[List[Option]] = None,
channel_types: Optional[List[ChannelType]] = None,
autocomplete: bool = False,
min_value: Optional[float] = None,
Expand Down Expand Up @@ -888,7 +888,7 @@ def add_option(
type: Optional[OptionType] = None,
required: bool = False,
choices: Optional[Choices] = None,
options: Optional[list] = None,
options: Optional[List[Option]] = None,
channel_types: Optional[List[ChannelType]] = None,
autocomplete: bool = False,
min_value: Optional[float] = None,
Expand Down
5 changes: 4 additions & 1 deletion disnake/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ async def read(self) -> bytes:
return await self._state.http.get_from_cdn(self.url)

async def save(
self, fp: Union[str, bytes, os.PathLike, io.BufferedIOBase], *, seek_begin: bool = True
self,
fp: Union[str, bytes, os.PathLike[str], os.PathLike[bytes], io.BufferedIOBase],
*,
seek_begin: bool = True,
) -> int:
"""|coro|

Expand Down
8 changes: 4 additions & 4 deletions disnake/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3404,7 +3404,7 @@ async def create_thread(
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
components: Components[MessageUIComponent] = ...,
reason: Optional[str] = None,
) -> ThreadWithMessage:
...
Expand All @@ -3425,7 +3425,7 @@ async def create_thread(
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
components: Components[MessageUIComponent] = ...,
reason: Optional[str] = None,
) -> ThreadWithMessage:
...
Expand All @@ -3446,7 +3446,7 @@ async def create_thread(
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
components: Components[MessageUIComponent] = ...,
reason: Optional[str] = None,
) -> ThreadWithMessage:
...
Expand All @@ -3467,7 +3467,7 @@ async def create_thread(
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = ...,
allowed_mentions: AllowedMentions = ...,
view: View = ...,
components: Components = ...,
components: Components[MessageUIComponent] = ...,
reason: Optional[str] = None,
) -> ThreadWithMessage:
...
Expand Down
6 changes: 4 additions & 2 deletions disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,14 @@ def __init__(
loop=self.loop,
)

self._handlers: Dict[str, Callable] = {
self._handlers: Dict[str, Callable[..., Any]] = {
"ready": self._handle_ready,
"connect_internal": self._handle_first_connect,
}

self._hooks: Dict[str, Callable] = {"before_identify": self._call_before_identify_hook}
self._hooks: Dict[str, Callable[..., Any]] = {
"before_identify": self._call_before_identify_hook
}

self._enable_debug_events: bool = enable_debug_events
self._enable_gateway_error_handler: bool = enable_gateway_error_handler
Expand Down
22 changes: 11 additions & 11 deletions disnake/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class InteractionException(ClientException):
The interaction that was responded to.
"""

interaction: Interaction
interaction: Interaction[Any]


class InteractionTimedOut(InteractionException):
Expand All @@ -330,8 +330,8 @@ class InteractionTimedOut(InteractionException):
The interaction that was responded to.
"""

def __init__(self, interaction: Interaction) -> None:
self.interaction: Interaction = interaction
def __init__(self, interaction: Interaction[Any]) -> None:
self.interaction: Interaction[Any] = interaction

msg = (
"Interaction took more than 3 seconds to be responded to. "
Expand Down Expand Up @@ -359,8 +359,8 @@ class InteractionResponded(InteractionException):
The interaction that's already been responded to.
"""

def __init__(self, interaction: Interaction) -> None:
self.interaction: Interaction = interaction
def __init__(self, interaction: Interaction[Any]) -> None:
self.interaction: Interaction[Any] = interaction
super().__init__("This interaction has already been responded to before")


Expand All @@ -378,8 +378,8 @@ class InteractionNotResponded(InteractionException):
The interaction that hasn't been responded to.
"""

def __init__(self, interaction: Interaction) -> None:
self.interaction: Interaction = interaction
def __init__(self, interaction: Interaction[Any]) -> None:
self.interaction: Interaction[Any] = interaction
super().__init__("This interaction hasn't been responded to yet")


Expand All @@ -394,8 +394,8 @@ class ModalChainNotSupported(InteractionException):
The interaction that was responded to.
"""

def __init__(self, interaction: ModalInteraction) -> None:
self.interaction: ModalInteraction = interaction
def __init__(self, interaction: ModalInteraction[Any]) -> None:
self.interaction: ModalInteraction[Any] = interaction
super().__init__("You cannot respond to a modal with another modal.")


Expand All @@ -411,8 +411,8 @@ class InteractionNotEditable(InteractionException):
The interaction that was responded to.
"""

def __init__(self, interaction: Interaction) -> None:
self.interaction: Interaction = interaction
def __init__(self, interaction: Interaction[Any]) -> None:
self.interaction: Interaction[Any] = interaction
super().__init__("This interaction does not have a message to edit.")


Expand Down
30 changes: 16 additions & 14 deletions disnake/ext/commands/base_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from .cog import Cog

ApplicationCommandInteractionT = TypeVar(
"ApplicationCommandInteractionT", bound=ApplicationCommandInteraction, covariant=True
"ApplicationCommandInteractionT", bound=ApplicationCommandInteraction[Any], covariant=True
)

P = ParamSpec("P")
Expand Down Expand Up @@ -282,7 +282,7 @@ def remove_check(self, func: AppCheck) -> None:
pass

async def __call__(
self, interaction: ApplicationCommandInteraction, *args: Any, **kwargs: Any
self, interaction: ApplicationCommandInteraction[Any], *args: Any, **kwargs: Any
) -> Any:
"""|coro|

Expand All @@ -300,7 +300,7 @@ async def __call__(
else:
return await self.callback(interaction, *args, **kwargs)

def _prepare_cooldowns(self, inter: ApplicationCommandInteraction) -> None:
def _prepare_cooldowns(self, inter: ApplicationCommandInteraction[Any]) -> None:
if self._buckets.valid:
dt = inter.created_at
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
Expand All @@ -310,7 +310,7 @@ def _prepare_cooldowns(self, inter: ApplicationCommandInteraction) -> None:
if retry_after:
raise CommandOnCooldown(bucket, retry_after, self._buckets.type) # type: ignore

async def prepare(self, inter: ApplicationCommandInteraction) -> None:
async def prepare(self, inter: ApplicationCommandInteraction[Any]) -> None:
inter.application_command = self

if not await self.can_run(inter):
Expand All @@ -327,7 +327,7 @@ async def prepare(self, inter: ApplicationCommandInteraction) -> None:
await self._max_concurrency.release(inter) # type: ignore
raise

def is_on_cooldown(self, inter: ApplicationCommandInteraction) -> bool:
def is_on_cooldown(self, inter: ApplicationCommandInteraction[Any]) -> bool:
"""Checks whether the application command is currently on cooldown.

Parameters
Expand All @@ -348,7 +348,7 @@ def is_on_cooldown(self, inter: ApplicationCommandInteraction) -> bool:
current = dt.replace(tzinfo=datetime.timezone.utc).timestamp()
return bucket.get_tokens(current) == 0

def reset_cooldown(self, inter: ApplicationCommandInteraction) -> None:
def reset_cooldown(self, inter: ApplicationCommandInteraction[Any]) -> None:
"""Resets the cooldown on this application command.

Parameters
Expand All @@ -360,7 +360,7 @@ def reset_cooldown(self, inter: ApplicationCommandInteraction) -> None:
bucket = self._buckets.get_bucket(inter) # type: ignore
bucket.reset()

def get_cooldown_retry_after(self, inter: ApplicationCommandInteraction) -> float:
def get_cooldown_retry_after(self, inter: ApplicationCommandInteraction[Any]) -> float:
"""Retrieves the amount of seconds before this application command can be tried again.

Parameters
Expand All @@ -383,7 +383,9 @@ def get_cooldown_retry_after(self, inter: ApplicationCommandInteraction) -> floa
return 0.0

# This method isn't really usable in this class, but it's usable in subclasses.
async def invoke(self, inter: ApplicationCommandInteraction, *args: Any, **kwargs: Any) -> None:
async def invoke(
self, inter: ApplicationCommandInteraction[Any], *args: Any, **kwargs: Any
) -> None:
await self.prepare(inter)

try:
Expand Down Expand Up @@ -429,7 +431,7 @@ def has_error_handler(self) -> bool:
return hasattr(self, "on_error")

async def _call_local_error_handler(
self, inter: ApplicationCommandInteraction, error: CommandError
self, inter: ApplicationCommandInteraction[Any], error: CommandError
) -> Any:
if not self.has_error_handler():
return
Expand All @@ -441,18 +443,18 @@ async def _call_local_error_handler(
return await injected(inter, error)

async def _call_external_error_handlers(
self, inter: ApplicationCommandInteraction, error: CommandError
self, inter: ApplicationCommandInteraction[Any], error: CommandError
) -> None:
"""Overridden in subclasses"""
raise error

async def dispatch_error(
self, inter: ApplicationCommandInteraction, error: CommandError
self, inter: ApplicationCommandInteraction[Any], error: CommandError
) -> None:
if not await self._call_local_error_handler(inter, error):
await self._call_external_error_handlers(inter, error)

async def call_before_hooks(self, inter: ApplicationCommandInteraction) -> None:
async def call_before_hooks(self, inter: ApplicationCommandInteraction[Any]) -> None:
# now that we're done preparing we can call the pre-command hooks
# first, call the command local hook:
cog = self.cog
Expand Down Expand Up @@ -487,7 +489,7 @@ async def call_before_hooks(self, inter: ApplicationCommandInteraction) -> None:
if hook is not None:
await hook(inter)

async def call_after_hooks(self, inter: ApplicationCommandInteraction) -> None:
async def call_after_hooks(self, inter: ApplicationCommandInteraction[Any]) -> None:
cog = self.cog
if self._after_invoke is not None:
instance = getattr(self._after_invoke, "__self__", cog)
Expand Down Expand Up @@ -568,7 +570,7 @@ def cog_name(self) -> Optional[str]:
"""Optional[:class:`str`]: The name of the cog this application command belongs to, if any."""
return type(self.cog).__cog_name__ if self.cog is not None else None

async def can_run(self, inter: ApplicationCommandInteraction) -> bool:
async def can_run(self, inter: ApplicationCommandInteraction[Any]) -> bool:
"""|coro|

Checks if the command can be executed by checking all the predicates
Expand Down
10 changes: 5 additions & 5 deletions disnake/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import disnake

from .bot_base import BotBase, when_mentioned, when_mentioned_or
from .bot_base import BotBase, CogT, when_mentioned, when_mentioned_or
from .interaction_bot_base import InteractionBotBase

if TYPE_CHECKING:
Expand Down Expand Up @@ -42,7 +42,7 @@
MISSING: Any = disnake.utils.MISSING


class Bot(BotBase, InteractionBotBase, disnake.Client):
class Bot(BotBase[CogT], InteractionBotBase[CogT], disnake.Client):
"""Represents a discord bot.

This class is a subclass of :class:`disnake.Client` and as a result
Expand Down Expand Up @@ -264,7 +264,7 @@ def __init__(
...


class AutoShardedBot(BotBase, InteractionBotBase, disnake.AutoShardedClient):
class AutoShardedBot(BotBase[CogT], InteractionBotBase[CogT], disnake.AutoShardedClient):
"""Similar to :class:`.Bot`, except that it is inherited from
:class:`disnake.AutoShardedClient` instead.
"""
Expand Down Expand Up @@ -316,7 +316,7 @@ def __init__(
...


class InteractionBot(InteractionBotBase, disnake.Client):
class InteractionBot(InteractionBotBase[CogT], disnake.Client):
"""Represents a discord bot for application commands only.

This class is a subclass of :class:`disnake.Client` and as a result
Expand Down Expand Up @@ -465,7 +465,7 @@ def __init__(
...


class AutoShardedInteractionBot(InteractionBotBase, disnake.AutoShardedClient):
class AutoShardedInteractionBot(InteractionBotBase[CogT], disnake.AutoShardedClient):
"""Similar to :class:`.InteractionBot`, except that it is inherited from
:class:`disnake.AutoShardedClient` instead.
"""
Expand Down
Loading
Loading