Merge pull request #12

* Clean up python

* Clean up bot python

* revert lists

* revert commands.bot completely

* extract raise_expected_coro further

* add new lines

* removed erroneous import

* remove hashed line
This commit is contained in:
chillymosh
2021-09-02 20:32:46 +01:00
committed by GitHub
parent 092fbca08f
commit 42c0a8d8a5
9 changed files with 74 additions and 84 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
__all__ = (
'loop',
@ -488,11 +490,7 @@ class Loop(Generic[LF]):
The function was not a coroutine.
"""
if not inspect.iscoroutinefunction(coro):
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__!r}.')
self._before_loop = coro
return 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.
@ -516,11 +514,7 @@ class Loop(Generic[LF]):
The function was not a coroutine.
"""
if not inspect.iscoroutinefunction(coro):
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__!r}.')
self._after_loop = coro
return 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.
@ -542,11 +536,7 @@ class Loop(Generic[LF]):
TypeError
The function was not a coroutine.
"""
if not inspect.iscoroutinefunction(coro):
raise TypeError(f'Expected coroutine function, received {coro.__class__.__name__!r}.')
self._error = coro # type: ignore
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:
@ -614,8 +604,7 @@ class Loop(Generic[LF]):
)
ret.append(t if t.tzinfo is not None else t.replace(tzinfo=utc))
ret = sorted(set(ret)) # de-dupe and sort times
return ret
return sorted(set(ret))
def change_interval(
self,