Preserve type hints (checked with mypy) for function decorated with aiocache's @cached decorator

31 Views Asked by At

Python version: 3.9.17

When I decorate a function with @cached, mypy will simply accept calls to the decorated function with invalid args. Making the typed params in the decorated function useless. How do I make mypy understand that it should flag calls to the decorated function that don't follow it's function signature?

aka:

from aiocache import cached

@cached
def foo_cached(x: str) -> str:
  return x

def foo(x: str) -> str:
  return x

foo_cached() # mypy is fine with this.
foo() # mypy flags this, as it's missing arg for param 'x'.

looking for a solution that works for python 3.9

0

There are 0 best solutions below