Issue29203
Created on 2017-01-08 10:01 by rhettinger, last changed 2017-01-09 07:27 by serhiy.storchaka. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| lru_468.diff | rhettinger, 2017-01-08 10:01 | review | ||
| lru_cache_pep468.patch | serhiy.storchaka, 2017-01-08 11:52 | review | ||
| Messages (6) | |||
|---|---|---|---|
| msg284971 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2017-01-08 10:01 | |
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. |
|||
| msg284972 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2017-01-08 10:25 | |
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. |
|||
| msg284973 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2017-01-08 10:35 | |
> I think this is a bug and it should be fixed in 3.6. I concur. Do you care to whip-up a patch (it is late here). |
|||
| msg284984 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2017-01-08 11:52 | |
Here is a patch that fixes also C implementation and has tests. |
|||
| msg285013 - (view) | Author: Roundup Robot (python-dev) | Date: 2017-01-09 01:29 | |
New changeset 48c750c26710 by Raymond Hettinger in branch '3.6': Issue #29203: functools.lru_cache() now respects PEP 468 https://hg.python.org/cpython/rev/48c750c26710 |
|||
| msg285014 - (view) | Author: Roundup Robot (python-dev) | Date: 2017-01-09 02:04 | |
New changeset cc47d385512b by Raymond Hettinger in branch 'default': Complete the merge for issue #29203 https://hg.python.org/cpython/rev/cc47d385512b |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2017-01-09 07:27:42 | serhiy.storchaka | set | stage: patch review -> resolved |
| 2017-01-09 07:21:45 | rhettinger | set | status: open -> closed resolution: fixed |
| 2017-01-09 02:04:38 | python-dev | set | messages: + msg285014 |
| 2017-01-09 01:29:38 | python-dev | set | nosy:
+ python-dev messages: + msg285013 |
| 2017-01-08 11:52:03 | serhiy.storchaka | set | files:
+ lru_cache_pep468.patch type: performance -> behavior messages: + msg284984 versions: + Python 3.6 |
| 2017-01-08 10:35:38 | rhettinger | set | messages: + msg284973 |
| 2017-01-08 10:25:24 | serhiy.storchaka | set | messages: + msg284972 |
| 2017-01-08 10:01:29 | rhettinger | create | |