mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-18 23:15:48 +00:00
[commands] Add missing and fix existing type annotations
This commit is contained in:
parent
46b3e036e2
commit
eca4727593
@ -45,18 +45,20 @@ else:
|
||||
P = TypeVar('P')
|
||||
MaybeCoroFunc = Tuple[P, T]
|
||||
|
||||
_Bot = Union['Bot', 'AutoShardedBot']
|
||||
Coro = Coroutine[Any, Any, T]
|
||||
MaybeCoro = Union[T, Coro[T]]
|
||||
CoroFunc = Callable[..., Coro[Any]]
|
||||
|
||||
ContextT = TypeVar('ContextT', bound='Context')
|
||||
_Bot = Union['Bot', 'AutoShardedBot']
|
||||
BotT = TypeVar('BotT', bound=_Bot, covariant=True)
|
||||
|
||||
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]]]
|
||||
|
||||
ContextT = TypeVar('ContextT', bound='Context[Any]')
|
||||
BotT = TypeVar('BotT', bound=_Bot, covariant=True)
|
||||
ErrorT = TypeVar('ErrorT', bound='Error[Context[Any]]')
|
||||
HookT = TypeVar('HookT', bound='Hook[Context[Any]]')
|
||||
|
||||
|
||||
# This is merely a tag type to avoid circular import issues.
|
||||
# Yes, this is a terrible solution but ultimately it is the only solution.
|
||||
|
@ -151,7 +151,7 @@ class BotBase(GroupMixin[None]):
|
||||
def __init__(
|
||||
self,
|
||||
command_prefix: PrefixType[BotT],
|
||||
help_command: Optional[HelpCommand] = _default,
|
||||
help_command: Optional[HelpCommand[Any]] = _default,
|
||||
description: Optional[str] = None,
|
||||
**options: Any,
|
||||
) -> None:
|
||||
@ -166,7 +166,7 @@ class BotBase(GroupMixin[None]):
|
||||
self._check_once: List[Check] = []
|
||||
self._before_invoke: Optional[CoroFunc] = None
|
||||
self._after_invoke: Optional[CoroFunc] = None
|
||||
self._help_command: Optional[HelpCommand] = None
|
||||
self._help_command: Optional[HelpCommand[Any]] = None
|
||||
self.description: str = inspect.cleandoc(description) if description else ''
|
||||
self.owner_id: Optional[int] = options.get('owner_id')
|
||||
self.owner_ids: Optional[Collection[int]] = options.get('owner_ids', set())
|
||||
@ -989,11 +989,11 @@ class BotBase(GroupMixin[None]):
|
||||
# help command stuff
|
||||
|
||||
@property
|
||||
def help_command(self) -> Optional[HelpCommand]:
|
||||
def help_command(self) -> Optional[HelpCommand[Any]]:
|
||||
return self._help_command
|
||||
|
||||
@help_command.setter
|
||||
def help_command(self, value: Optional[HelpCommand]) -> None:
|
||||
def help_command(self, value: Optional[HelpCommand[Any]]) -> None:
|
||||
if value is not None:
|
||||
if not isinstance(value, HelpCommand):
|
||||
raise TypeError('help_command must be a subclass of HelpCommand')
|
||||
|
@ -68,6 +68,8 @@ if TYPE_CHECKING:
|
||||
Check,
|
||||
Hook,
|
||||
Error,
|
||||
ErrorT,
|
||||
HookT,
|
||||
)
|
||||
|
||||
|
||||
@ -105,7 +107,6 @@ CogT = TypeVar('CogT', bound='Optional[Cog]')
|
||||
CommandT = TypeVar('CommandT', bound='Command')
|
||||
# CHT = TypeVar('CHT', bound='Check')
|
||||
GroupT = TypeVar('GroupT', bound='Group')
|
||||
FuncT = TypeVar('FuncT', bound=Callable[..., Any])
|
||||
|
||||
if TYPE_CHECKING:
|
||||
P = ParamSpec('P')
|
||||
@ -920,7 +921,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
if call_hooks:
|
||||
await self.call_after_hooks(ctx)
|
||||
|
||||
def error(self, coro: FuncT) -> FuncT:
|
||||
def error(self, coro: ErrorT) -> ErrorT:
|
||||
"""A decorator that registers a coroutine as a local error handler.
|
||||
|
||||
A local error handler is an :func:`.on_command_error` event limited to
|
||||
@ -951,7 +952,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
"""
|
||||
return hasattr(self, 'on_error')
|
||||
|
||||
def before_invoke(self, coro: FuncT) -> FuncT:
|
||||
def before_invoke(self, coro: HookT) -> HookT:
|
||||
"""A decorator that registers a coroutine as a pre-invoke hook.
|
||||
|
||||
A pre-invoke hook is called directly before the command is
|
||||
@ -978,7 +979,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
self._before_invoke = coro
|
||||
return coro
|
||||
|
||||
def after_invoke(self, coro: FuncT) -> FuncT:
|
||||
def after_invoke(self, coro: HookT) -> HookT:
|
||||
"""A decorator that registers a coroutine as a post-invoke hook.
|
||||
|
||||
A post-invoke hook is called directly after the command is
|
||||
@ -2319,7 +2320,7 @@ def max_concurrency(number: int, per: BucketType = BucketType.default, *, wait:
|
||||
return decorator # type: ignore
|
||||
|
||||
|
||||
def before_invoke(coro) -> Callable[[T], T]:
|
||||
def before_invoke(coro: Hook[ContextT]) -> Callable[[T], T]:
|
||||
"""A decorator that registers a coroutine as a pre-invoke hook.
|
||||
|
||||
This allows you to refer to one before invoke hook for several commands that
|
||||
@ -2367,7 +2368,7 @@ def before_invoke(coro) -> Callable[[T], T]:
|
||||
return decorator # type: ignore
|
||||
|
||||
|
||||
def after_invoke(coro) -> Callable[[T], T]:
|
||||
def after_invoke(coro: Hook[ContextT]) -> Callable[[T], T]:
|
||||
"""A decorator that registers a coroutine as a post-invoke hook.
|
||||
|
||||
This allows you to refer to one after invoke hook for several commands that
|
||||
|
@ -262,6 +262,7 @@ class HelpCommand(HelpCommandCommand, Generic[ContextT]):
|
||||
) -> None:
|
||||
self.show_hidden: bool = show_hidden
|
||||
self.verify_checks: bool = verify_checks
|
||||
self.command_attrs: Dict[str, Any]
|
||||
self.command_attrs = attrs = command_attrs if command_attrs is not MISSING else {}
|
||||
attrs.setdefault('name', 'help')
|
||||
attrs.setdefault('help', 'Shows this message')
|
||||
|
Loading…
x
Reference in New Issue
Block a user