From 590818ba4a8c38d521117cb75b4cf52d77ffc19a Mon Sep 17 00:00:00 2001 From: Suren Khorenyan Date: Sun, 17 Apr 2022 11:58:53 +0300 Subject: [PATCH] hotfix https://github.com/mahenzon/aioalice/issues/16 CancelledError import --- aioalice/dispatcher/webhook.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/aioalice/dispatcher/webhook.py b/aioalice/dispatcher/webhook.py index 019dd2a..5918435 100644 --- a/aioalice/dispatcher/webhook.py +++ b/aioalice/dispatcher/webhook.py @@ -1,12 +1,23 @@ import asyncio import logging import functools +import sys +from typing import TYPE_CHECKING from aiohttp import web from aioalice.utils import json, generate_json_payload from aioalice.types import AliceRequest, AliceResponse, Response +if sys.version_info >= (3, 7): + from asyncio import CancelledError +else: + from asyncio.futures import CancelledError + + +if TYPE_CHECKING: + from aioalice import Dispatcher + log = logging.getLogger(__name__) @@ -46,7 +57,7 @@ class WebhookRequestHandler(web.View): """ - def get_dispatcher(self): + def get_dispatcher(self) -> "Dispatcher": """ Get Dispatcher instance from environment """ @@ -74,7 +85,7 @@ async def process_request(self, request): :param request: :return: """ - dispatcher = self.get_dispatcher() + dispatcher: "Dispatcher" = self.get_dispatcher() loop = dispatcher.loop # Analog of `asyncio.wait_for` but without cancelling task @@ -88,7 +99,7 @@ async def process_request(self, request): try: try: await waiter - except asyncio.futures.CancelledError: + except CancelledError: fut.remove_done_callback(done_cb) fut.cancel() raise