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:
@@ -25,7 +25,6 @@ DEALINGS IN THE SOFTWARE.
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
import asyncio
|
||||
import collections
|
||||
import collections.abc
|
||||
import inspect
|
||||
@@ -53,7 +52,7 @@ from typing import (
|
||||
import discord
|
||||
from discord import app_commands
|
||||
from discord.app_commands.tree import _retrieve_guild_ids
|
||||
from discord.utils import MISSING, _is_submodule
|
||||
from discord.utils import MISSING, _iscoroutinefunction, _is_submodule
|
||||
|
||||
from .core import GroupMixin
|
||||
from .view import StringView
|
||||
@@ -581,7 +580,7 @@ class BotBase(GroupMixin[None]):
|
||||
TypeError
|
||||
The coroutine passed is not actually a coroutine.
|
||||
"""
|
||||
if not asyncio.iscoroutinefunction(coro):
|
||||
if not _iscoroutinefunction(coro):
|
||||
raise TypeError('The pre-invoke hook must be a coroutine.')
|
||||
|
||||
self._before_invoke = coro
|
||||
@@ -618,7 +617,7 @@ class BotBase(GroupMixin[None]):
|
||||
TypeError
|
||||
The coroutine passed is not actually a coroutine.
|
||||
"""
|
||||
if not asyncio.iscoroutinefunction(coro):
|
||||
if not _iscoroutinefunction(coro):
|
||||
raise TypeError('The post-invoke hook must be a coroutine.')
|
||||
|
||||
self._after_invoke = coro
|
||||
@@ -654,7 +653,7 @@ class BotBase(GroupMixin[None]):
|
||||
"""
|
||||
name = func.__name__ if name is MISSING else name
|
||||
|
||||
if not asyncio.iscoroutinefunction(func):
|
||||
if not _iscoroutinefunction(func):
|
||||
raise TypeError('Listeners must be coroutines')
|
||||
|
||||
if name in self.extra_events:
|
||||
|
||||
@@ -28,7 +28,7 @@ import inspect
|
||||
import discord
|
||||
import logging
|
||||
from discord import app_commands
|
||||
from discord.utils import maybe_coroutine, _to_kebab_case
|
||||
from discord.utils import maybe_coroutine, _iscoroutinefunction, _to_kebab_case
|
||||
|
||||
from typing import (
|
||||
Any,
|
||||
@@ -233,7 +233,7 @@ class CogMeta(type):
|
||||
if elem.startswith(('cog_', 'bot_')):
|
||||
raise TypeError(no_bot_cog.format(base, elem))
|
||||
cog_app_commands[elem] = value
|
||||
elif inspect.iscoroutinefunction(value):
|
||||
elif _iscoroutinefunction(value):
|
||||
try:
|
||||
getattr(value, '__cog_listener__')
|
||||
except AttributeError:
|
||||
@@ -522,7 +522,7 @@ class Cog(metaclass=CogMeta):
|
||||
actual = func
|
||||
if isinstance(actual, staticmethod):
|
||||
actual = actual.__func__
|
||||
if not inspect.iscoroutinefunction(actual):
|
||||
if not _iscoroutinefunction(actual):
|
||||
raise TypeError('Listener function must be a coroutine function.')
|
||||
actual.__cog_listener__ = True
|
||||
to_assign = name or actual.__name__
|
||||
|
||||
@@ -427,7 +427,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
/,
|
||||
**kwargs: Unpack[_CommandKwargs],
|
||||
) -> None:
|
||||
if not asyncio.iscoroutinefunction(func):
|
||||
if not discord.utils._iscoroutinefunction(func):
|
||||
raise TypeError('Callback must be a coroutine.')
|
||||
|
||||
name = kwargs.get('name') or func.__name__
|
||||
@@ -1102,7 +1102,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
The coroutine passed is not actually a coroutine.
|
||||
"""
|
||||
|
||||
if not asyncio.iscoroutinefunction(coro):
|
||||
if not discord.utils._iscoroutinefunction(coro):
|
||||
raise TypeError('The error handler must be a coroutine.')
|
||||
|
||||
self.on_error: Error[CogT, Any] = coro
|
||||
@@ -1140,7 +1140,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
TypeError
|
||||
The coroutine passed is not actually a coroutine.
|
||||
"""
|
||||
if not asyncio.iscoroutinefunction(coro):
|
||||
if not discord.utils._iscoroutinefunction(coro):
|
||||
raise TypeError('The pre-invoke hook must be a coroutine.')
|
||||
|
||||
self._before_invoke = coro
|
||||
@@ -1171,7 +1171,7 @@ class Command(_BaseCommand, Generic[CogT, P, T]):
|
||||
TypeError
|
||||
The coroutine passed is not actually a coroutine.
|
||||
"""
|
||||
if not asyncio.iscoroutinefunction(coro):
|
||||
if not discord.utils._iscoroutinefunction(coro):
|
||||
raise TypeError('The post-invoke hook must be a coroutine.')
|
||||
|
||||
self._after_invoke = coro
|
||||
@@ -1945,7 +1945,7 @@ def check(predicate: UserCheck[ContextT], /) -> Check[ContextT]:
|
||||
|
||||
return func
|
||||
|
||||
if inspect.iscoroutinefunction(predicate):
|
||||
if discord.utils._iscoroutinefunction(predicate):
|
||||
decorator.predicate = predicate
|
||||
else:
|
||||
|
||||
@@ -2369,7 +2369,7 @@ def guild_only() -> Check[Any]:
|
||||
|
||||
return func
|
||||
|
||||
if inspect.iscoroutinefunction(predicate):
|
||||
if discord.utils._iscoroutinefunction(predicate):
|
||||
decorator.predicate = predicate
|
||||
else:
|
||||
|
||||
@@ -2444,7 +2444,7 @@ def is_nsfw() -> Check[Any]:
|
||||
|
||||
return func
|
||||
|
||||
if inspect.iscoroutinefunction(predicate):
|
||||
if discord.utils._iscoroutinefunction(predicate):
|
||||
decorator.predicate = predicate
|
||||
else:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user