Skip to content

Commit

Permalink
Use ContextT everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
Soheab committed Feb 6, 2025
1 parent db7b2d9 commit 66a5ee7
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 93 deletions.
6 changes: 3 additions & 3 deletions discord/ext/commands/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def decorator(func: CommandCallback[Any, ContextT, P, T]):

# Error handler

async def on_command_error(self, context: Context[BotT], exception: errors.CommandError, /) -> None:
async def on_command_error(self, context: ContextT, exception: errors.CommandError, /) -> None:

Check warning on line 329 in discord/ext/commands/bot.py

View workflow job for this annotation

GitHub Actions / check 3.x

TypeVar "ContextT" appears only once in generic function signature   Use "Context[Any]" instead (reportInvalidTypeVarUse)
"""|coro|
The default command error handler provided by the bot.
Expand Down Expand Up @@ -481,7 +481,7 @@ def whitelist(ctx):
self.add_check(func, call_once=True)
return func

async def can_run(self, ctx: Context[BotT], /, *, call_once: bool = False) -> bool:
async def can_run(self, ctx: ContextT, /, *, call_once: bool = False) -> bool:

Check warning on line 484 in discord/ext/commands/bot.py

View workflow job for this annotation

GitHub Actions / check 3.x

TypeVar "ContextT" appears only once in generic function signature   Use "Context[Any]" instead (reportInvalidTypeVarUse)
data = self._check_once if call_once else self._checks

if len(data) == 0:
Expand Down Expand Up @@ -1344,7 +1344,7 @@ class be provided, it must be similar enough to :class:`.Context`\'s
ctx.command = self.all_commands.get(invoker)
return ctx

async def invoke(self, ctx: Context[BotT], /) -> None:
async def invoke(self, ctx: ContextT, /) -> None:

Check warning on line 1347 in discord/ext/commands/bot.py

View workflow job for this annotation

GitHub Actions / check 3.x

TypeVar "ContextT" appears only once in generic function signature   Use "Context[Any]" instead (reportInvalidTypeVarUse)
"""|coro|
Invokes the command given under the invocation context and
Expand Down
13 changes: 7 additions & 6 deletions discord/ext/commands/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from .bot import BotBase
from .context import Context

Check failure on line 57 in discord/ext/commands/cog.py

View workflow job for this annotation

GitHub Actions / check 3.x

Import "Context" is not accessed (reportUnusedImport)
from .core import Command
from ._types import ContextT

__all__ = (
'CogMeta',
Expand Down Expand Up @@ -581,7 +582,7 @@ async def cog_unload(self) -> None:
pass

@_cog_special_method
def bot_check_once(self, ctx: Context[BotT]) -> bool:
def bot_check_once(self, ctx: ContextT) -> bool:

Check warning on line 585 in discord/ext/commands/cog.py

View workflow job for this annotation

GitHub Actions / check 3.x

TypeVar "ContextT" appears only once in generic function signature   Use "Context[Any]" instead (reportInvalidTypeVarUse)
"""A special method that registers as a :meth:`.Bot.check_once`
check.
Expand All @@ -591,7 +592,7 @@ def bot_check_once(self, ctx: Context[BotT]) -> bool:
return True

@_cog_special_method
def bot_check(self, ctx: Context[BotT]) -> bool:
def bot_check(self, ctx: ContextT) -> bool:

Check warning on line 595 in discord/ext/commands/cog.py

View workflow job for this annotation

GitHub Actions / check 3.x

TypeVar "ContextT" appears only once in generic function signature   Use "Context[Any]" instead (reportInvalidTypeVarUse)
"""A special method that registers as a :meth:`.Bot.check`
check.
Expand All @@ -601,7 +602,7 @@ def bot_check(self, ctx: Context[BotT]) -> bool:
return True

@_cog_special_method
def cog_check(self, ctx: Context[BotT]) -> bool:
def cog_check(self, ctx: ContextT) -> bool:

Check warning on line 605 in discord/ext/commands/cog.py

View workflow job for this annotation

GitHub Actions / check 3.x

TypeVar "ContextT" appears only once in generic function signature   Use "Context[Any]" instead (reportInvalidTypeVarUse)
"""A special method that registers as a :func:`~discord.ext.commands.check`
for every command and subcommand in this cog.
Expand All @@ -623,7 +624,7 @@ def interaction_check(self, interaction: discord.Interaction[ClientT], /) -> boo
return True

@_cog_special_method
async def cog_command_error(self, ctx: Context[BotT], error: Exception) -> None:
async def cog_command_error(self, ctx: ContextT, error: Exception) -> None:

Check warning on line 627 in discord/ext/commands/cog.py

View workflow job for this annotation

GitHub Actions / check 3.x

TypeVar "ContextT" appears only once in generic function signature   Use "Context[Any]" instead (reportInvalidTypeVarUse)
"""|coro|
A special method that is called whenever an error
Expand Down Expand Up @@ -665,7 +666,7 @@ async def cog_app_command_error(self, interaction: discord.Interaction, error: a
pass

@_cog_special_method
async def cog_before_invoke(self, ctx: Context[BotT]) -> None:
async def cog_before_invoke(self, ctx: ContextT) -> None:
"""|coro|
A special method that acts as a cog local pre-invoke hook.
Expand All @@ -682,7 +683,7 @@ async def cog_before_invoke(self, ctx: Context[BotT]) -> None:
pass

@_cog_special_method
async def cog_after_invoke(self, ctx: Context[BotT]) -> None:
async def cog_after_invoke(self, ctx: ContextT) -> None:
"""|coro|
A special method that acts as a cog local post-invoke hook.
Expand Down
5 changes: 3 additions & 2 deletions discord/ext/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from .parameters import Parameter

from types import TracebackType
from ._types import ContextT

BE = TypeVar('BE', bound=BaseException)

Expand All @@ -83,8 +84,8 @@ def is_cog(obj: Any) -> TypeGuard[Cog]:


class DeferTyping:
def __init__(self, ctx: Context[BotT], *, ephemeral: bool):
self.ctx: Context[BotT] = ctx
def __init__(self, ctx: ContextT, *, ephemeral: bool):
self.ctx: ContextT = ctx
self.ephemeral: bool = ephemeral

async def do_defer(self) -> None:
Expand Down
Loading

0 comments on commit 66a5ee7

Please sign in to comment.