thadeusb / flask-cache

Cache extension for Flask
http://packages.python.org/Flask-Cache/
Other
697 stars 185 forks source link

support memorizing function with typehinted arguments #196

Closed haolian9 closed 5 years ago

haolian9 commented 5 years ago

reproducing:

env:

code:

@cache.memorize()
def add(a: float, b: float):
    return z + b

add(1, 2)

output:

Exception possibly due to cache backend.
Traceback (most recent call last):
  File "project/venv/lib64/python3.6/site-packages/flask_cache/__init__.py", line 528, in decorated_function
    cache_key = decorated_function.make_cache_key(f, *args, **kwargs)
  File "project/venv/lib64/python3.6/site-packages/flask_cache/__init__.py", line 381, in make_cache_key
    timeout=_timeout)
  File "project/venv/lib64/python3.6/site-packages/flask_cache/__init__.py", line 336, in _memoize_version
    fname, instance_fname = function_namespace(f, args=args)
  File "project/venv/lib64/python3.6/site-packages/flask_cache/__init__.py", line 45, in function_namespace
    m_args = inspect.getargspec(f)[0]
  File "/usr/lib64/python3.6/inspect.py", line 1080, in getargspec
    raise ValueError("Function has keyword-only parameters or annotations"
ValueError: Function has keyword-only parameters or annotations, use getfullargspec() API which can support them