aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2019-04-11 08:19:50 -0400
committerRapptz <[email protected]>2019-04-11 08:21:45 -0400
commit4513dac7a37ec0c554e6c1051ccf42e5f264a1cb (patch)
tree3284da66918f3ca0306509681138e3973bd2f94c
parent[tasks] Rename Loop.run to Loop.start to avoid blocking connotations (diff)
downloaddiscord.py-4513dac7a37ec0c554e6c1051ccf42e5f264a1cb.tar.xz
discord.py-4513dac7a37ec0c554e6c1051ccf42e5f264a1cb.zip
[tasks] Ensure total number of seconds is not less than 0.
-rw-r--r--discord/ext/tasks/__init__.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/discord/ext/tasks/__init__.py b/discord/ext/tasks/__init__.py
index 1c5c791a..91e49c3a 100644
--- a/discord/ext/tasks/__init__.py
+++ b/discord/ext/tasks/__init__.py
@@ -40,7 +40,11 @@ class Loop:
self._sleep = sleep = self.seconds + (self.minutes * 60.0) + (self.hours * 3600.0)
if sleep >= MAX_ASYNCIO_SECONDS:
- raise ValueError('Total time exceeds asyncio imposed limit of {0} seconds.'.format(MAX_ASYNCIO_SECONDS))
+ fmt = 'Total number of seconds exceeds asyncio imposed limit of {0} seconds.'
+ raise ValueError(fmt.format(MAX_ASYNCIO_SECONDS))
+
+ if sleep < 0:
+ raise ValueError('Total number of seconds cannot be less than zero.')
if not inspect.iscoroutinefunction(self.coro):
raise TypeError('Expected coroutine function, not {0!r}.'.format(type(self.coro)))
@@ -74,7 +78,6 @@ class Loop:
""":class:`int`: The current iteration of the loop."""
return self._current_loop
-
def start(self, *args, **kwargs):
r"""Starts the internal task in the event loop.
@@ -205,5 +208,5 @@ def loop(*, seconds=0, minutes=0, hours=0, count=None, reconnect=True, loop=None
"""
def decorator(func):
return Loop(func, seconds=seconds, minutes=minutes, hours=hours,
- count=count, reconnect=reconnect, loop=loop)
+ count=count, reconnect=reconnect, loop=loop)
return decorator