[commands] Fix typing of check/check_any

This changes the type information of check decorators to return a
protocol representing that the decorator leaves the underlying object
unchanged while having a .predicate attribute.

resolves #7949
This commit is contained in:
Michael H
2022-05-02 18:54:49 -04:00
committed by GitHub
parent 4a73de946a
commit d0667d08e3
4 changed files with 36 additions and 26 deletions

View File

@ -73,7 +73,7 @@ if TYPE_CHECKING:
from ._types import (
_Bot,
BotT,
Check,
UserCheck,
CoroFunc,
ContextT,
MaybeAwaitableFunc,
@ -173,8 +173,8 @@ class BotBase(GroupMixin[None]):
self.__tree: app_commands.CommandTree[Self] = tree_cls(self) # type: ignore
self.__cogs: Dict[str, Cog] = {}
self.__extensions: Dict[str, types.ModuleType] = {}
self._checks: List[Check] = []
self._check_once: List[Check] = []
self._checks: List[UserCheck] = []
self._check_once: List[UserCheck] = []
self._before_invoke: Optional[CoroFunc] = None
self._after_invoke: Optional[CoroFunc] = None
self._help_command: Optional[HelpCommand] = None
@ -359,7 +359,7 @@ class BotBase(GroupMixin[None]):
self.add_check(func) # type: ignore
return func
def add_check(self, func: Check[ContextT], /, *, call_once: bool = False) -> None:
def add_check(self, func: UserCheck[ContextT], /, *, call_once: bool = False) -> None:
"""Adds a global check to the bot.
This is the non-decorator interface to :meth:`.check`
@ -383,7 +383,7 @@ class BotBase(GroupMixin[None]):
else:
self._checks.append(func)
def remove_check(self, func: Check[ContextT], /, *, call_once: bool = False) -> None:
def remove_check(self, func: UserCheck[ContextT], /, *, call_once: bool = False) -> None:
"""Removes a global check from the bot.
This function is idempotent and will not raise an exception