Skip to content

Commit

Permalink
Make type-anno compatible with Python 3.8 (#338)
Browse files Browse the repository at this point in the history
  • Loading branch information
achimnol committed Apr 25, 2023
1 parent a99043e commit 9f776e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions aiomonitor/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"persistent_coro",
)

persistent_coro: weakref.WeakSet[Coroutine] = weakref.WeakSet()
persistent_coro: "weakref.WeakSet[Coroutine]" = weakref.WeakSet()

T = TypeVar("T")
P = ParamSpec("P")
Expand Down Expand Up @@ -59,7 +59,7 @@ def get_trace_id(self) -> str:
b = struct.pack("P", h)
return base64.b32encode(b).rstrip(b"=").decode()

def _trace_termination(self, _: asyncio.Task[Any]) -> None:
def _trace_termination(self, _: "asyncio.Task[Any]") -> None:
self_id = self.get_trace_id()
exc_repr = (
repr(self.exception())
Expand Down
10 changes: 5 additions & 5 deletions aiomonitor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .types import TerminatedTaskInfo


def _format_task(task: asyncio.Task[Any]) -> str:
def _format_task(task: "asyncio.Task[Any]") -> str:
"""
A simpler version of task's repr()
"""
Expand Down Expand Up @@ -111,7 +111,7 @@ def _filter_stack(


def _extract_stack_from_task(
task: asyncio.Task[Any],
task: "asyncio.Task[Any]",
) -> List[traceback.FrameSummary]:
"""
Extracts the stack as a list of FrameSummary objects from an asyncio task.
Expand Down Expand Up @@ -232,18 +232,18 @@ def format_commands(self, ctx, formatter):

def task_by_id(
taskid: int, loop: asyncio.AbstractEventLoop
) -> Optional[asyncio.Task[Any]]:
) -> "Optional[asyncio.Task[Any]]":
tasks = all_tasks(loop=loop)
return next(filter(lambda t: id(t) == taskid, tasks), None)


async def cancel_task(task: asyncio.Task[Any]) -> None:
async def cancel_task(task: "asyncio.Task[Any]") -> None:
with contextlib.suppress(asyncio.CancelledError):
task.cancel()
await task


def all_tasks(loop: asyncio.AbstractEventLoop) -> Set[asyncio.Task[Any]]:
def all_tasks(loop: asyncio.AbstractEventLoop) -> "Set[asyncio.Task[Any]]":
if sys.version_info >= (3, 7):
tasks = asyncio.all_tasks(loop=loop)
else:
Expand Down

0 comments on commit 9f776e9

Please sign in to comment.