extract raise_expected_coro further

This commit is contained in:
chillymosh
2021-08-28 22:52:58 +01:00
parent 1829048c80
commit 73a4996aa9
3 changed files with 30 additions and 36 deletions

View File

@@ -46,7 +46,9 @@ import traceback
from collections.abc import Sequence
from discord.backoff import ExponentialBackoff
from discord.utils import MISSING
from discord.utils import MISSING, raise_expected_coro
#from discord.utils import raise_expected_coro
__all__ = (
'loop',
@@ -488,7 +490,7 @@ class Loop(Generic[LF]):
The function was not a coroutine.
"""
return self._raise_expected_coro(coro)
return raise_expected_coro(coro, f'Expected coroutine function, received {coro.__class__.__name__!r}.')
def after_loop(self, coro: FT) -> FT:
"""A decorator that register a coroutine to be called after the loop finished running.
@@ -512,7 +514,7 @@ class Loop(Generic[LF]):
The function was not a coroutine.
"""
return self._raise_expected_coro(coro)
return raise_expected_coro(coro, f'Expected coroutine function, received {coro.__class__.__name__!r}.')
def error(self, coro: ET) -> ET:
"""A decorator that registers a coroutine to be called if the task encounters an unhandled exception.
@@ -534,15 +536,7 @@ class Loop(Generic[LF]):
TypeError
The function was not a coroutine.
"""
return self._raise_expected_coro(coro)
def _raise_expected_coro(self, coro):
if not inspect.iscoroutinefunction(coro):
raise TypeError(
f'Expected coroutine function, received {coro.__class__.__name__!r}.'
)
return coro
return raise_expected_coro(coro, f'Expected coroutine function, received {coro.__class__.__name__!r}.')
def _get_next_sleep_time(self) -> datetime.datetime:
if self._sleep is not MISSING: