From 880e93570037c32490cc741e5f124691059e84d6 Mon Sep 17 00:00:00 2001 From: Boger Date: Sat, 28 Mar 2020 19:43:35 +0300 Subject: [PATCH] Return old hack, because new break mypy plugins :face_with_rolling_eyes: --- aiogram/dispatcher/filters/base.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/aiogram/dispatcher/filters/base.py b/aiogram/dispatcher/filters/base.py index af712c70..a71c484a 100644 --- a/aiogram/dispatcher/filters/base.py +++ b/aiogram/dispatcher/filters/base.py @@ -1,26 +1,28 @@ from abc import ABC, abstractmethod from typing import ( - Awaitable, - Callable, + TYPE_CHECKING, Any, Dict, Union, + Callable, + Awaitable, ) from pydantic import BaseModel -async def _call_for_override(*args: Any, **kwargs: Any) -> Union[bool, Dict[str, Any]]: # pragma: no cover - pass - - class BaseFilter(ABC, BaseModel): - # This little hack with typehint is needed because mypy checks validity of overrides and raises: - # error: Signature of "__call__" incompatible with supertype "BaseFilter" [override] - # https://mypy.readthedocs.io/en/latest/error_code_list.html#check-validity-of-overrides-override - __call__: Callable[..., Awaitable[Union[bool, Dict[str, Any]]]] = _call_for_override - abstractmethod(__call__) + if TYPE_CHECKING: # pragma: no cover + # This checking type-hint is needed because mypy checks validity of overrides and raises: + # error: Signature of "__call__" incompatible with supertype "BaseFilter" [override] + # https://mypy.readthedocs.io/en/latest/error_code_list.html#check-validity-of-overrides-override + __call__: Callable[..., Awaitable[Union[bool, Dict[str, Any]]]] + else: # pragma: no cover - def __await__(self): # type: ignore # pragma: no cover + @abstractmethod + async def __call__(self, *args: Any, **kwargs: Any) -> Union[bool, Dict[str, Any]]: + pass + + def __await__(self): # type: ignore # pragma: no cover # Is needed only for inspection and this method is never be called return self.__call__