Skip to content

Commit cc8f27f

Browse files
committed
♻️ move maybe_coroutine to private
1 parent 6b0379c commit cc8f27f

File tree

9 files changed

+20
-21
lines changed

9 files changed

+20
-21
lines changed

discord/commands/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@
6868
from ..role import Role
6969
from ..threads import Thread
7070
from ..user import User
71-
from ..utils import MISSING, find, maybe_coroutine, utcnow
72-
from ..utils.private import warn_deprecated, async_all
71+
from ..utils import MISSING, find, utcnow
72+
from ..utils.private import warn_deprecated, async_all, maybe_coroutine
7373
from .context import ApplicationContext, AutocompleteContext
7474
from .options import Option, OptionChoice
7575

discord/ext/commands/bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ async def get_prefix(self, message: Message) -> list[str] | str:
224224
"""
225225
prefix = ret = self.command_prefix
226226
if callable(prefix):
227-
ret = await discord.utils.maybe_coroutine(prefix, self, message)
227+
ret = await discord.utils.private.maybe_coroutine(prefix, self, message)
228228

229229
if not isinstance(ret, str):
230230
try:

discord/ext/commands/core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ async def can_run(self, ctx: Context) -> bool:
11471147
if cog is not None:
11481148
local_check = Cog._get_overridden_method(cog.cog_check)
11491149
if local_check is not None:
1150-
ret = await discord.utils.maybe_coroutine(local_check, ctx)
1150+
ret = await discord.utils.private.maybe_coroutine(local_check, ctx)
11511151
if not ret:
11521152
return False
11531153

discord/ext/commands/flags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
from typing import TYPE_CHECKING, Any, Iterator, Literal, Pattern, TypeVar, Union
3333

3434
from discord import utils
35-
from ...utils import MISSING, Undefined, maybe_coroutine
36-
from ...utils.private import resolve_annotation
35+
from ...utils import MISSING, Undefined
36+
from ...utils.private import resolve_annotation, maybe_coroutine
3737

3838
from .converter import run_converters
3939
from .errors import (

discord/ext/commands/help.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from typing import TYPE_CHECKING, Any
3333

3434
from ... import utils
35-
from ...utils.private import string_width
35+
from ...utils.private import string_width, maybe_coroutine
3636

3737
from .core import Command, Group
3838
from .errors import CommandError
@@ -868,18 +868,18 @@ async def command_callback(self, ctx, *, command=None):
868868
keys = command.split(" ")
869869
cmd = bot.all_commands.get(keys[0])
870870
if cmd is None:
871-
string = await utils.maybe_coroutine(self.command_not_found, self.remove_mentions(keys[0]))
871+
string = await maybe_coroutine(self.command_not_found, self.remove_mentions(keys[0]))
872872
return await self.send_error_message(string)
873873

874874
for key in keys[1:]:
875875
try:
876876
found = cmd.all_commands.get(key)
877877
except AttributeError:
878-
string = await utils.maybe_coroutine(self.subcommand_not_found, cmd, self.remove_mentions(key))
878+
string = await maybe_coroutine(self.subcommand_not_found, cmd, self.remove_mentions(key))
879879
return await self.send_error_message(string)
880880
else:
881881
if found is None:
882-
string = await utils.maybe_coroutine(self.subcommand_not_found, cmd, self.remove_mentions(key))
882+
string = await maybe_coroutine(self.subcommand_not_found, cmd, self.remove_mentions(key))
883883
return await self.send_error_message(string)
884884
cmd = found
885885

discord/iterators.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
from .audit_logs import AuditLogEntry
4242
from .errors import NoMoreItems
4343
from .object import Object
44-
from .utils import generate_snowflake, maybe_coroutine, snowflake_time
44+
from .utils import generate_snowflake, snowflake_time
45+
from .utils.private import maybe_coroutine
4546

4647
__all__ = (
4748
"ReactionIterator",

discord/utils/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import json
3333
import re
3434
from bisect import bisect_left
35-
from inspect import isawaitable
3635
from inspect import signature as _signature
3736
from typing import (
3837
TYPE_CHECKING,
@@ -304,14 +303,6 @@ def _to_json(obj: Any) -> str:
304303
_from_json = json.loads
305304

306305

307-
async def maybe_coroutine(f, *args, **kwargs):
308-
value = f(*args, **kwargs)
309-
if isawaitable(value):
310-
return await value
311-
else:
312-
return value
313-
314-
315306
async def sane_wait_for(futures, *, timeout):
316307
ensured = [asyncio.ensure_future(fut) for fut in futures]
317308
done, pending = await asyncio.wait(ensured, timeout=timeout, return_when=asyncio.ALL_COMPLETED)

discord/utils/private.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,11 @@ async def async_all(gen: Iterable[Any]) -> bool:
392392
if not elem:
393393
return False
394394
return True
395+
396+
397+
async def maybe_coroutine(f, *args, **kwargs):
398+
value = f(*args, **kwargs)
399+
if isawaitable(value):
400+
return await value
401+
else:
402+
return value

tests/test_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
find,
3636
generate_snowflake,
3737
get,
38-
maybe_coroutine,
3938
snowflake_time,
4039
utcnow,
4140
)

0 commit comments

Comments
 (0)