mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-20 16:00:29 +00:00
[commands] Simplify typing of command hooks
This commit is contained in:
parent
c907bec753
commit
9d3fa3d29b
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user