mirror of
https://github.com/Rapptz/discord.py.git
synced 2026-09-21 03:27:42 +00:00
Use iscoroutinefunction from inspect instead of asyncio on 3.12+
This commit is contained in:
@@ -58,7 +58,16 @@ from ..message import Message
|
||||
from ..user import User
|
||||
from ..member import Member
|
||||
from ..permissions import Permissions
|
||||
from ..utils import resolve_annotation, MISSING, is_inside_class, maybe_coroutine, async_all, _shorten, _to_kebab_case
|
||||
from ..utils import (
|
||||
resolve_annotation,
|
||||
MISSING,
|
||||
is_inside_class,
|
||||
maybe_coroutine,
|
||||
async_all,
|
||||
_iscoroutinefunction,
|
||||
_shorten,
|
||||
_to_kebab_case,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing_extensions import ParamSpec, Concatenate, Unpack
|
||||
@@ -346,7 +355,7 @@ def _populate_autocomplete(params: Dict[str, CommandParameter], autocomplete: Di
|
||||
if callback is MISSING:
|
||||
continue
|
||||
|
||||
if not inspect.iscoroutinefunction(callback):
|
||||
if not _iscoroutinefunction(callback):
|
||||
raise TypeError('autocomplete callback must be a coroutine function')
|
||||
|
||||
if param.type not in (AppCommandOptionType.string, AppCommandOptionType.number, AppCommandOptionType.integer):
|
||||
@@ -1037,7 +1046,7 @@ class Command(Generic[GroupT, P, T]):
|
||||
The coroutine passed is not actually a coroutine.
|
||||
"""
|
||||
|
||||
if not inspect.iscoroutinefunction(coro):
|
||||
if not _iscoroutinefunction(coro):
|
||||
raise TypeError('The error handler must be a coroutine.')
|
||||
|
||||
self.on_error = coro
|
||||
@@ -1098,7 +1107,7 @@ class Command(Generic[GroupT, P, T]):
|
||||
"""
|
||||
|
||||
def decorator(coro: AutocompleteCallback[GroupT, ChoiceT]) -> AutocompleteCallback[GroupT, ChoiceT]:
|
||||
if not inspect.iscoroutinefunction(coro):
|
||||
if not _iscoroutinefunction(coro):
|
||||
raise TypeError('The autocomplete callback must be a coroutine function.')
|
||||
|
||||
try:
|
||||
@@ -1347,7 +1356,7 @@ class ContextMenu:
|
||||
The coroutine passed is not actually a coroutine.
|
||||
"""
|
||||
|
||||
if not inspect.iscoroutinefunction(coro):
|
||||
if not _iscoroutinefunction(coro):
|
||||
raise TypeError('The error handler must be a coroutine.')
|
||||
|
||||
self.on_error = coro
|
||||
@@ -1840,7 +1849,7 @@ class Group:
|
||||
The coroutine passed is not actually a coroutine, or is an invalid coroutine.
|
||||
"""
|
||||
|
||||
if not inspect.iscoroutinefunction(coro):
|
||||
if not _iscoroutinefunction(coro):
|
||||
raise TypeError('The error handler must be a coroutine.')
|
||||
|
||||
params = inspect.signature(coro).parameters
|
||||
@@ -1990,7 +1999,7 @@ class Group:
|
||||
"""
|
||||
|
||||
def decorator(func: CommandCallback[GroupT, P, T]) -> Command[GroupT, P, T]:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
if not _iscoroutinefunction(func):
|
||||
raise TypeError('command function must be a coroutine function')
|
||||
|
||||
if description is MISSING:
|
||||
@@ -2051,7 +2060,7 @@ def command(
|
||||
"""
|
||||
|
||||
def decorator(func: CommandCallback[GroupT, P, T]) -> Command[GroupT, P, T]:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
if not _iscoroutinefunction(func):
|
||||
raise TypeError('command function must be a coroutine function')
|
||||
|
||||
if description is MISSING:
|
||||
@@ -2123,7 +2132,7 @@ def context_menu(
|
||||
"""
|
||||
|
||||
def decorator(func: ContextMenuCallback) -> ContextMenu:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
if not _iscoroutinefunction(func):
|
||||
raise TypeError('context menu function must be a coroutine function')
|
||||
|
||||
actual_name = func.__name__.title() if name is MISSING else name
|
||||
|
||||
@@ -53,7 +53,7 @@ from ..channel import StageChannel, VoiceChannel, TextChannel, CategoryChannel,
|
||||
from ..abc import GuildChannel
|
||||
from ..threads import Thread
|
||||
from ..enums import Enum as InternalEnum, AppCommandOptionType, ChannelType, Locale
|
||||
from ..utils import MISSING, maybe_coroutine, _human_join, TIMESTAMP_PATTERN
|
||||
from ..utils import MISSING, maybe_coroutine, _human_join, _iscoroutinefunction, TIMESTAMP_PATTERN
|
||||
from ..user import User
|
||||
from ..role import Role
|
||||
from ..member import Member
|
||||
@@ -814,7 +814,7 @@ def get_supported_annotation(
|
||||
params = inspect.signature(transform_classmethod.__func__).parameters
|
||||
if len(params) != 3:
|
||||
raise TypeError('Inline transformer with transform classmethod requires 3 parameters')
|
||||
if not inspect.iscoroutinefunction(transform_classmethod.__func__):
|
||||
if not _iscoroutinefunction(transform_classmethod.__func__):
|
||||
raise TypeError('Inline transformer with transform classmethod must be a coroutine')
|
||||
return (InlineTransformer(annotation), MISSING, False)
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ from .installs import AppCommandContext, AppInstallationType
|
||||
from .translator import Translator, locale_str
|
||||
from ..errors import ClientException, HTTPException
|
||||
from ..enums import AppCommandType, InteractionType
|
||||
from ..utils import MISSING, _get_as_snowflake, _is_submodule, _shorten
|
||||
from ..utils import MISSING, _get_as_snowflake, _iscoroutinefunction, _is_submodule, _shorten
|
||||
from .._types import ClientT
|
||||
|
||||
|
||||
@@ -839,7 +839,7 @@ class CommandTree(Generic[ClientT]):
|
||||
not match the signature.
|
||||
"""
|
||||
|
||||
if not inspect.iscoroutinefunction(coro):
|
||||
if not _iscoroutinefunction(coro):
|
||||
raise TypeError('The error handler must be a coroutine.')
|
||||
|
||||
params = inspect.signature(coro).parameters
|
||||
@@ -908,7 +908,7 @@ class CommandTree(Generic[ClientT]):
|
||||
"""
|
||||
|
||||
def decorator(func: CommandCallback[Group, P, T]) -> Command[Group, P, T]:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
if not _iscoroutinefunction(func):
|
||||
raise TypeError('command function must be a coroutine function')
|
||||
|
||||
if description is MISSING:
|
||||
@@ -1005,7 +1005,7 @@ class CommandTree(Generic[ClientT]):
|
||||
"""
|
||||
|
||||
def decorator(func: ContextMenuCallback) -> ContextMenu:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
if not _iscoroutinefunction(func):
|
||||
raise TypeError('context menu function must be a coroutine function')
|
||||
|
||||
actual_name = func.__name__.title() if name is MISSING else name
|
||||
|
||||
Reference in New Issue
Block a user