From 7ba153c7b16d7aa274476ca5632a1648fff471ea Mon Sep 17 00:00:00 2001 From: sabbyX Date: Sun, 4 Oct 2020 20:56:34 +0530 Subject: [PATCH] HandlerObject: Unwrap handler before awaitable check (#435) * Unwrap handler before awaitable check * Remove unused 'type:ignore' comment * Add wrapped handler tests --- aiogram/dispatcher/event/handler.py | 3 ++- tests/test_dispatcher/test_handler/test_base.py | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aiogram/dispatcher/event/handler.py b/aiogram/dispatcher/event/handler.py index 6c2a5e57..8314c52b 100644 --- a/aiogram/dispatcher/event/handler.py +++ b/aiogram/dispatcher/event/handler.py @@ -61,7 +61,8 @@ class HandlerObject(CallableMixin): def __post_init__(self) -> None: super(HandlerObject, self).__post_init__() - if inspect.isclass(self.callback) and issubclass(self.callback, BaseHandler): # type: ignore + callback = inspect.unwrap(self.callback) + if inspect.isclass(callback) and issubclass(callback, BaseHandler): self.awaitable = True async def check(self, *args: Any, **kwargs: Any) -> Tuple[bool, Dict[str, Any]]: diff --git a/tests/test_dispatcher/test_handler/test_base.py b/tests/test_dispatcher/test_handler/test_base.py index 21063b62..48550702 100644 --- a/tests/test_dispatcher/test_handler/test_base.py +++ b/tests/test_dispatcher/test_handler/test_base.py @@ -1,11 +1,13 @@ import asyncio import datetime +from functools import wraps from typing import Any import pytest from aiogram import Bot from aiogram.api.types import Chat, Message, Update +from aiogram.dispatcher.event.handler import HandlerObject from aiogram.dispatcher.handler.base import BaseHandler @@ -56,3 +58,9 @@ class TestBaseClassBasedHandler: assert handler.event == event assert handler.update == update + + @pytest.mark.asyncio + async def test_wrapped_handler(self): + # wrap the handler on dummy function + handler = wraps(MyHandler)(lambda: None) + assert HandlerObject(handler).awaitable is True