aboutsummaryrefslogtreecommitdiffstats
path: root/botcore
diff options
context:
space:
mode:
authorGravatar Hassan Abouelela <[email protected]>2022-06-26 21:42:07 +0400
committerGravatar Hassan Abouelela <[email protected]>2022-06-26 21:42:07 +0400
commit5efb69b2070ee972dd58401c06c0313513593a38 (patch)
treee26309ae1a620353c3d52fe67cb92fac4a4f3225 /botcore
parentDocument Create Task Return Type (diff)
Replace Typing Generics
Replaces all typing generics with collection equivalents as per PEP 585. `typing.Callable` was not included in this due to a sphinx-autodoc bug not handling it well. Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'botcore')
-rw-r--r--botcore/utils/members.py3
-rw-r--r--botcore/utils/scheduling.py15
2 files changed, 10 insertions, 8 deletions
diff --git a/botcore/utils/members.py b/botcore/utils/members.py
index 10513953..1536a8d1 100644
--- a/botcore/utils/members.py
+++ b/botcore/utils/members.py
@@ -1,5 +1,6 @@
"""Useful helper functions for interactin with :obj:`discord.Member` objects."""
import typing
+from collections import abc
import discord
@@ -29,7 +30,7 @@ async def get_or_fetch_member(guild: discord.Guild, member_id: int) -> typing.Op
async def handle_role_change(
member: discord.Member,
- coro: typing.Callable[[discord.Role], typing.Coroutine],
+ coro: typing.Callable[[discord.Role], abc.Coroutine],
role: discord.Role
) -> None:
"""
diff --git a/botcore/utils/scheduling.py b/botcore/utils/scheduling.py
index 8d2f875e..8e30d63b 100644
--- a/botcore/utils/scheduling.py
+++ b/botcore/utils/scheduling.py
@@ -4,6 +4,7 @@ import asyncio
import contextlib
import inspect
import typing
+from collections import abc
from datetime import datetime
from functools import partial
@@ -38,7 +39,7 @@ class Scheduler:
self.name = name
self._log = logging.get_logger(f"{__name__}.{name}")
- self._scheduled_tasks: typing.Dict[typing.Hashable, asyncio.Task] = {}
+ self._scheduled_tasks: dict[typing.Hashable, asyncio.Task] = {}
def __contains__(self, task_id: typing.Hashable) -> bool:
"""
@@ -52,7 +53,7 @@ class Scheduler:
"""
return task_id in self._scheduled_tasks
- def schedule(self, task_id: typing.Hashable, coroutine: typing.Coroutine) -> None:
+ def schedule(self, task_id: typing.Hashable, coroutine: abc.Coroutine) -> None:
"""
Schedule the execution of a ``coroutine``.
@@ -79,7 +80,7 @@ class Scheduler:
self._scheduled_tasks[task_id] = task
self._log.debug(f"Scheduled task #{task_id} {id(task)}.")
- def schedule_at(self, time: datetime, task_id: typing.Hashable, coroutine: typing.Coroutine) -> None:
+ def schedule_at(self, time: datetime, task_id: typing.Hashable, coroutine: abc.Coroutine) -> None:
"""
Schedule ``coroutine`` to be executed at the given ``time``.
@@ -107,7 +108,7 @@ class Scheduler:
self,
delay: typing.Union[int, float],
task_id: typing.Hashable,
- coroutine: typing.Coroutine
+ coroutine: abc.Coroutine
) -> None:
"""
Schedule ``coroutine`` to be executed after ``delay`` seconds.
@@ -151,7 +152,7 @@ class Scheduler:
self,
delay: typing.Union[int, float],
task_id: typing.Hashable,
- coroutine: typing.Coroutine
+ coroutine: abc.Coroutine
) -> None:
"""Await ``coroutine`` after ``delay`` seconds."""
try:
@@ -212,7 +213,7 @@ TASK_RETURN = typing.TypeVar("TASK_RETURN")
def create_task(
- coro: typing.Coroutine[typing.Any, typing.Any, TASK_RETURN],
+ coro: abc.Coroutine[typing.Any, typing.Any, TASK_RETURN],
*,
suppressed_exceptions: tuple[typing.Type[Exception]] = (),
event_loop: typing.Optional[asyncio.AbstractEventLoop] = None,
@@ -241,7 +242,7 @@ def create_task(
return task
-def _log_task_exception(task: asyncio.Task, *, suppressed_exceptions: typing.Tuple[typing.Type[Exception]]) -> None:
+def _log_task_exception(task: asyncio.Task, *, suppressed_exceptions: tuple[type[Exception]]) -> None:
"""Retrieve and log the exception raised in ``task`` if one exists."""
with contextlib.suppress(asyncio.CancelledError):
exception = task.exception()