Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cache decorators doesn't support kwargs #62

Closed
ardeois opened this issue May 1, 2014 · 2 comments
Closed

cache decorators doesn't support kwargs #62

ardeois opened this issue May 1, 2014 · 2 comments

Comments

@ardeois
Copy link

ardeois commented May 1, 2014

I'm using the decorator 'cache_region' and it's not possible to cache a function which has kwargs :

@cache_region('short_term')
def a_function(x, y=None):
  return 'whatever'

When invoking the function 'a_function', we get an exception like:

TypeError: cached() got an unexpected keyword argument 'y'

This behavior happens with any decorator for caching functions

@amol-
Copy link
Collaborator

amol- commented Feb 16, 2015

The proposed patch seems to have a flaw to me. The cache key is generated from the passed **kwargs and *args, this means that for a function defined as:

def a_function(x, y=None):
    return 'whatever'

calling it as a_function(1, 2) will lead to a different cache key than a_function(x=1, y=2) this is due to the fact that joined_kwargs is constructed depending on the actually passed function arguments, so it depends on the way the arguments are passed.

You should probably pass through inspect.getcallargs before generating the cache key so that it is unrealted to the way the function is called.

@amol-
Copy link
Collaborator

amol- commented Nov 13, 2015

This should now be solved by 6b89db7

@amol- amol- closed this as completed Nov 13, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants