Skip to content
New issue

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

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

Already on GitHub? # to your account

get_args_tuple() doesn't take **kwargs into account #83

Open
JelleZijlstra opened this issue Jan 10, 2022 · 1 comment
Open

get_args_tuple() doesn't take **kwargs into account #83

JelleZijlstra opened this issue Jan 10, 2022 · 1 comment

Comments

@JelleZijlstra
Copy link
Contributor

Running this:

import qcore

counter = 0


class X:
    @qcore.caching.cached_per_instance()
    def cached(self, **kwargs):
        global counter
        counter += 1
        return counter


x = X()
print(x.cached(a=1))
print(x.cached(a=2))

Prints 1, 1 (we'd expect 1, 2).

This is because the get_args_tuple() function (https://github.com/quora/qcore/blob/master/qcore/caching.py#L321) ignores **kwargs that are not recognized.

I see a few other problems:

  • *args isn't handled either
  • Python 3.8+ positional-only params are ignored.
@JelleZijlstra
Copy link
Contributor Author

Possible solutions:

  • Put something like tuple(kwargs.items()) in the cache key
  • Disallow cached functions that take **kwargs.

corey-sobel pushed a commit to corey-sobel/qcore that referenced this issue Jan 18, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant