HandlerObject: Unwrap handler before awaitable check (#435)

* Unwrap handler before awaitable check

* Remove unused 'type:ignore' comment

* Add wrapped handler tests
This commit is contained in:
sabbyX 2020-10-04 20:56:34 +05:30 committed by GitHub
parent 6f53f15577
commit 7ba153c7b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -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]]:

View file

@ -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