My last attempt to write a decorator that accepts any possible python function and passes mypy check with --disallow-any-decorated flag looked like this:
from typing import Any, Callable, TypeVar
T = TypeVar('T')
def decorator(func: Callable[..., T]) -> Callable[..., T]:
def decorated(*args: Any, **kwargs: Any) -> Any:
print('decorated')
return func(*args, **kwargs)
return decorated
@decorator
def foo() -> int:
print('foo')
return 42
print(foo())
However it still fails with Type of decorated function contains type "Any" ("Callable[..., int]")
What am I doing wrong? I also tried to use VarArg and KwArg from mypy_extensions instead of ..., but it didn't help.