For the following file:
from abc import ABC, abstractmethod
from typing import Any, Awaitable, Callable, TypeVar, cast
T = TypeVar('T')
def dec(args: Any) -> Callable[..., Awaitable[T]]:
def dec2(f: Callable[..., Awaitable[T]]) -> Awaitable[T]:
async def wrapper(*args:Any, **kwargs:Any) -> T:
print(args)
return cast(T, await f(*args, **kwargs))
return cast(Awaitable[T], wrapper)
return dec2
class A(ABC):
@abstractmethod
async def fn(self) -> 'bool':
pass
class B(A):
@dec('hi')
async def fn(self) -> 'bool':
return True
class C(A):
@dec('hi')
async def fn(self) -> 'bool':
return False
I am receiving the following mypy errors:
$ mypy typetest.py
typetest.py:24: error: Signature of "fn" incompatible with supertype "A"
typetest.py:30: error: Signature of "fn" incompatible with supertype "A"
Found 2 errors in 1 file (checked 1 source file)
How does the typing need to work in order to preserve the class signature and not receive the mypy error.
This is on python3.7 with mypy 0.790