mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Return old hack, because new break mypy plugins :face_with_rolling_eyes:
This commit is contained in:
parent
4298406bd2
commit
880e935700
1 changed files with 14 additions and 12 deletions
|
|
@ -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__
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue