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
With PEP 468, the lru cache not longer needs to sort keyword args #73389
Comments
Since the ordering of keyword arguments is now guaranteed, the LRU cache doesn't need to sort any longer. The will give a small change in behavior that I don't care about. A call f(a=1, b=2) would now be cached separately from f(b=2, a=1). That won't arise often and isn't really different than the status quo where f(1, b=2) or f(1, 2) are already cached separately. Overall it is a net win by saving the sorting step on every call. |
I think this is a bug and it should be fixed in 3.6. Currenly lru_cache breaks PEP-468 (Preserving Keyword Argument Order). >>> from functools import lru_cache
>>> @lru_cache()
... def f(**kwargs):
... return list(kwargs.items())
...
>>> f(a=1, b=2)
[('a', 1), ('b', 2)]
>>> f(b=2, a=1)
[('a', 1), ('b', 2)] C implementation should be changed too. |
I concur. Do you care to whip-up a patch (it is late here). |
Here is a patch that fixes also C implementation and has tests. |
New changeset 48c750c26710 by Raymond Hettinger in branch '3.6': |
New changeset cc47d385512b by Raymond Hettinger in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: