mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 20:28:38 +00:00
Formally document utils.maybe_coroutine
This commit is contained in:
parent
ed40d55f99
commit
469f006d8b
@ -91,6 +91,7 @@ __all__ = (
|
|||||||
'remove_markdown',
|
'remove_markdown',
|
||||||
'escape_markdown',
|
'escape_markdown',
|
||||||
'escape_mentions',
|
'escape_mentions',
|
||||||
|
'maybe_coroutine',
|
||||||
'as_chunks',
|
'as_chunks',
|
||||||
'format_dt',
|
'format_dt',
|
||||||
'MISSING',
|
'MISSING',
|
||||||
@ -657,6 +658,30 @@ def _parse_ratelimit_header(request: Any, *, use_clock: bool = False) -> float:
|
|||||||
|
|
||||||
|
|
||||||
async def maybe_coroutine(f: MaybeAwaitableFunc[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
|
async def maybe_coroutine(f: MaybeAwaitableFunc[P, T], *args: P.args, **kwargs: P.kwargs) -> T:
|
||||||
|
r"""|coro|
|
||||||
|
|
||||||
|
A helper function that will await the result of a function if it's a coroutine
|
||||||
|
or return the result if it's not.
|
||||||
|
|
||||||
|
This is useful for functions that may or may not be coroutines.
|
||||||
|
|
||||||
|
.. versionadded:: 2.2
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
-----------
|
||||||
|
f: Callable[..., Any]
|
||||||
|
The function or coroutine to call.
|
||||||
|
\*args
|
||||||
|
The arguments to pass to the function.
|
||||||
|
\*\*kwargs
|
||||||
|
The keyword arguments to pass to the function.
|
||||||
|
|
||||||
|
Returns
|
||||||
|
--------
|
||||||
|
Any
|
||||||
|
The result of the function or coroutine.
|
||||||
|
"""
|
||||||
|
|
||||||
value = f(*args, **kwargs)
|
value = f(*args, **kwargs)
|
||||||
if _isawaitable(value):
|
if _isawaitable(value):
|
||||||
return await value
|
return await value
|
||||||
|
@ -1398,6 +1398,8 @@ Utility Functions
|
|||||||
|
|
||||||
.. autofunction:: discord.utils.setup_logging
|
.. autofunction:: discord.utils.setup_logging
|
||||||
|
|
||||||
|
.. autofunction:: discord.utils.maybe_coroutine
|
||||||
|
|
||||||
.. autofunction:: discord.utils.snowflake_time
|
.. autofunction:: discord.utils.snowflake_time
|
||||||
|
|
||||||
.. autofunction:: discord.utils.time_snowflake
|
.. autofunction:: discord.utils.time_snowflake
|
||||||
|
Loading…
x
Reference in New Issue
Block a user