diff --git a/discord/ext/commands/_types.py b/discord/ext/commands/_types.py index 6cd941f1b..5f7192f0a 100644 --- a/discord/ext/commands/_types.py +++ b/discord/ext/commands/_types.py @@ -37,11 +37,11 @@ Coro = Coroutine[Any, Any, T] MaybeCoro = Union[T, Coro[T]] CoroFunc = Callable[..., Coro[Any]] -Check = Union[Callable[["Cog", "Context[Any]"], MaybeCoro[bool]], Callable[["Context[Any]"], MaybeCoro[bool]]] -Hook = Union[Callable[["Cog", "Context[Any]"], Coro[Any]], Callable[["Context[Any]"], Coro[Any]]] -Error = Union[ - Callable[["Cog", "Context[Any]", "CommandError"], Coro[Any]], Callable[["Context[Any]", "CommandError"], Coro[Any]] -] +ContextT = TypeVar('ContextT', bound='Context') + +Check = Union[Callable[["Cog", "ContextT"], MaybeCoro[bool]], Callable[["ContextT"], MaybeCoro[bool]]] +Hook = Union[Callable[["Cog", "ContextT"], Coro[Any]], Callable[["ContextT"], Coro[Any]]] +Error = Union[Callable[["Cog", "ContextT", "CommandError"], Coro[Any]], Callable[["ContextT", "CommandError"], Coro[Any]]] # This is merely a tag type to avoid circular import issues. diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index c04660016..95372c98d 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -104,8 +104,7 @@ CommandT = TypeVar('CommandT', bound='Command') ContextT = TypeVar('ContextT', bound='Context') # CHT = TypeVar('CHT', bound='Check') GroupT = TypeVar('GroupT', bound='Group') -HookT = TypeVar('HookT', bound='Hook') -ErrorT = TypeVar('ErrorT', bound='Error') +FuncT = TypeVar('FuncT', bound=Callable[..., Any]) if TYPE_CHECKING: P = ParamSpec('P') @@ -916,7 +915,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): if call_hooks: await self.call_after_hooks(ctx) - def error(self, coro: ErrorT) -> ErrorT: + def error(self, coro: FuncT) -> FuncT: """A decorator that registers a coroutine as a local error handler. A local error handler is an :func:`.on_command_error` event limited to @@ -947,7 +946,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): """ return hasattr(self, 'on_error') - def before_invoke(self, coro: HookT) -> HookT: + def before_invoke(self, coro: FuncT) -> FuncT: """A decorator that registers a coroutine as a pre-invoke hook. A pre-invoke hook is called directly before the command is @@ -974,7 +973,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]): self._before_invoke = coro return coro - def after_invoke(self, coro: HookT) -> HookT: + def after_invoke(self, coro: FuncT) -> FuncT: """A decorator that registers a coroutine as a post-invoke hook. A post-invoke hook is called directly after the command is