From 8b8829af866b536a990d9221f26047a91296fbdb Mon Sep 17 00:00:00 2001 From: miruka Date: Sun, 26 Apr 2020 13:49:44 -0400 Subject: [PATCH] Use asyncio.Task.current_task for python 3.6 --- src/backend/matrix_client.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index e9ea0211..43965085 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -8,6 +8,7 @@ import io import logging as log import platform import re +import sys import traceback from contextlib import suppress from copy import copy @@ -45,6 +46,11 @@ from .pyotherside_events import AlertRequested, LoopException if TYPE_CHECKING: from .backend import Backend +if sys.version_info >= (3, 7): + current_task = asyncio.current_task +else: + current_task = asyncio.Task.current_task + CryptDict = Dict[str, Any] @@ -403,7 +409,7 @@ class MatrixClient(nio.AsyncClient): self.models[room_id, "uploads"][str(item_uuid)] = upload_item self.upload_monitors[item_uuid] = monitor - self.upload_tasks[item_uuid] = asyncio.current_task() # type: ignore + self.upload_tasks[item_uuid] = current_task() # type: ignore def on_transferred(transferred: int) -> None: upload_item.uploaded = transferred @@ -655,7 +661,7 @@ class MatrixClient(nio.AsyncClient): """Send a message event with `content` dict to a room.""" self.send_message_tasks[transaction_id] = \ - asyncio.current_task() # type: ignore + current_task() # type: ignore async with self.backend.send_locks[room_id]: await self.room_send(