Return old hack, because new break mypy plugins :face_with_rolling_eyes:

This commit is contained in:
Boger 2020-03-28 19:43:35 +03:00
parent 4298406bd2
commit 880e935700

View file

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