mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 10:22:59 +00:00
Update types to use Awaitable where possible
This commit is contained in:
@ -23,7 +23,7 @@ DEALINGS IN THE SOFTWARE.
|
||||
"""
|
||||
|
||||
|
||||
from typing import Any, Callable, Coroutine, TYPE_CHECKING, TypeVar, Union, Tuple
|
||||
from typing import Any, Awaitable, Callable, Coroutine, TYPE_CHECKING, TypeVar, Union, Tuple
|
||||
|
||||
|
||||
T = TypeVar('T')
|
||||
@ -37,18 +37,16 @@ if TYPE_CHECKING:
|
||||
from .errors import CommandError
|
||||
|
||||
P = ParamSpec('P')
|
||||
MaybeCoroFunc = Union[
|
||||
Callable[P, 'Coro[T]'],
|
||||
Callable[P, T],
|
||||
]
|
||||
MaybeAwaitableFunc = Callable[P, 'MaybeAwaitable[T]']
|
||||
else:
|
||||
P = TypeVar('P')
|
||||
MaybeCoroFunc = Tuple[P, T]
|
||||
MaybeAwaitableFunc = Tuple[P, T]
|
||||
|
||||
_Bot = Union['Bot', 'AutoShardedBot']
|
||||
Coro = Coroutine[Any, Any, T]
|
||||
MaybeCoro = Union[T, Coro[T]]
|
||||
CoroFunc = Callable[..., Coro[Any]]
|
||||
MaybeCoro = Union[T, Coro[T]]
|
||||
MaybeAwaitable = Union[T, Awaitable[T]]
|
||||
|
||||
Check = Union[Callable[["Cog", "ContextT"], MaybeCoro[bool]], Callable[["ContextT"], MaybeCoro[bool]]]
|
||||
Hook = Union[Callable[["Cog", "ContextT"], Coro[Any]], Callable[["ContextT"], Coro[Any]]]
|
||||
|
@ -74,11 +74,11 @@ if TYPE_CHECKING:
|
||||
Check,
|
||||
CoroFunc,
|
||||
ContextT,
|
||||
MaybeCoroFunc,
|
||||
MaybeAwaitableFunc,
|
||||
)
|
||||
|
||||
_Prefix = Union[Iterable[str], str]
|
||||
_PrefixCallable = MaybeCoroFunc[[BotT, Message], _Prefix]
|
||||
_PrefixCallable = MaybeAwaitableFunc[[BotT, Message], _Prefix]
|
||||
PrefixType = Union[_Prefix, _PrefixCallable[BotT]]
|
||||
|
||||
__all__ = (
|
||||
|
@ -31,6 +31,7 @@ import re
|
||||
|
||||
from typing import (
|
||||
TYPE_CHECKING,
|
||||
Awaitable,
|
||||
Optional,
|
||||
Generator,
|
||||
Generic,
|
||||
@ -54,7 +55,6 @@ if TYPE_CHECKING:
|
||||
|
||||
import discord.abc
|
||||
|
||||
from ._types import Coro
|
||||
from .bot import BotBase
|
||||
from .cog import Cog
|
||||
from .context import Context
|
||||
@ -295,7 +295,7 @@ class HelpCommand(HelpCommandCommand, Generic[ContextT]):
|
||||
bot.remove_command(self.name)
|
||||
self._eject_cog()
|
||||
|
||||
async def _call_without_cog(self, callback: Callable[[ContextT], Coro[T]], ctx: ContextT) -> T:
|
||||
async def _call_without_cog(self, callback: Callable[[ContextT], Awaitable[T]], ctx: ContextT) -> T:
|
||||
cog = self._cog
|
||||
self.cog = None
|
||||
try:
|
||||
|
Reference in New Issue
Block a user