diff options
author | 2023-06-04 20:34:14 +0100 | |
---|---|---|
committer | 2023-06-04 20:34:14 +0100 | |
commit | 1a362c04eb4d5d8f3c531a590d73cf5d7300ace8 (patch) | |
tree | accbe4d840b036dcc9502eed395f19400f5ad9a3 /pydis_core/utils/scheduling.py | |
parent | Merge pull request #175 from python-discord/log-when-waiting-for-guild-to-be-... (diff) | |
parent | Add changelog entry for ruff migration (diff) |
Merge pull request #176 from python-discord/ruff-migration
Ruff migration
Diffstat (limited to 'pydis_core/utils/scheduling.py')
-rw-r--r-- | pydis_core/utils/scheduling.py | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/pydis_core/utils/scheduling.py b/pydis_core/utils/scheduling.py index d4458bc1..1e2e25e7 100644 --- a/pydis_core/utils/scheduling.py +++ b/pydis_core/utils/scheduling.py @@ -5,7 +5,7 @@ import contextlib import inspect import typing from collections import abc -from datetime import datetime +from datetime import datetime, timezone from functools import partial from pydis_core.utils import logging @@ -69,7 +69,8 @@ class Scheduler: self._log.trace(f"Scheduling task #{task_id}...") msg = f"Cannot schedule an already started coroutine for #{task_id}" - assert inspect.getcoroutinestate(coroutine) == "CORO_CREATED", msg + if inspect.getcoroutinestate(coroutine) != "CORO_CREATED": + raise ValueError(msg) if task_id in self._scheduled_tasks: self._log.debug(f"Did not schedule task #{task_id}; task was already scheduled.") @@ -99,7 +100,7 @@ class Scheduler: task_id: A unique ID to create the task with. coroutine: The function to be called. """ - now_datetime = datetime.now(time.tzinfo) if time.tzinfo else datetime.utcnow() + now_datetime = datetime.now(time.tzinfo) if time.tzinfo else datetime.now(tz=timezone.utc) delay = (time - now_datetime).total_seconds() if delay > 0: coroutine = self._await_later(delay, task_id, coroutine) @@ -108,7 +109,7 @@ class Scheduler: def schedule_later( self, - delay: typing.Union[int, float], + delay: int | float, task_id: abc.Hashable, coroutine: abc.Coroutine ) -> None: @@ -152,7 +153,7 @@ class Scheduler: async def _await_later( self, - delay: typing.Union[int, float], + delay: int | float, task_id: abc.Hashable, coroutine: abc.Coroutine ) -> None: @@ -218,7 +219,7 @@ def create_task( coro: abc.Coroutine[typing.Any, typing.Any, TASK_RETURN], *, suppressed_exceptions: tuple[type[Exception], ...] = (), - event_loop: typing.Optional[asyncio.AbstractEventLoop] = None, + event_loop: asyncio.AbstractEventLoop | None = None, **kwargs, ) -> asyncio.Task[TASK_RETURN]: """ |