lonelyenvoy / python-memoization

A powerful caching library for Python, with TTL support and multiple algorithm options.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

cached does not preserve type signature

bmc-msft opened this issue · comments

Using cached does not preserve the type signature.

from memoization import cached
import inspect


def foo(a: str) -> int:
    return int(a)


def bar(a: str) -> int:
    return int(a)


@cached
def baz(a: str) -> int:
    return int(a)


assert inspect.getfullargspec(foo) == inspect.getfullargspec(bar), "foo != bar"
assert inspect.getfullargspec(foo) == inspect.getfullargspec(baz), "foo != baz"

Expected: No output

Actual result:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AssertionError: foo != baz

This prevents using type validation tools, such as mypy, from being used to validate the usage of methods wrapped in cached.

Resolved in v0.3.2. Now available at PyPI or GitHub Releases.

I also added full support for static type checking and it should work fine with validation tools.
Thanks for the issue and your interest in this work.