Closed
Labels
3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
Description
| BPO | 40571 |
|---|---|
| Nosy | @rhettinger |
| PRs |
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:
assignee = None
closed_at = <Date 2020-05-12.00:01:23.494>
created_at = <Date 2020-05-08.21:22:40.410>
labels = ['type-feature', 'library', '3.9']
title = 'Make lru_cache(maxsize=None) more discoverable'
updated_at = <Date 2020-05-12.00:01:23.493>
user = 'https://github.com/rhettinger'bugs.python.org fields:
activity = <Date 2020-05-12.00:01:23.493>
actor = 'rhettinger'
assignee = 'none'
closed = True
closed_date = <Date 2020-05-12.00:01:23.494>
closer = 'rhettinger'
components = ['Library (Lib)']
creation = <Date 2020-05-08.21:22:40.410>
creator = 'rhettinger'
dependencies = []
files = []
hgrepos = []
issue_num = 40571
keywords = ['patch']
message_count = 3.0
messages = ['368469', '368471', '368684']
nosy_count = 1.0
nosy_names = ['rhettinger']
pr_nums = ['20019']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue40571'
versions = ['Python 3.9']Metadata
Metadata
Assignees
Labels
3.9 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancement
Activity
rhettinger commentedon May 8, 2020
The recent discussions on python-ideas showed that people have a hard time finding the infinity-cache option for lru_cache(). Also, in the context of straight caching without limits, the name *lru_cache()* makes the tool seem complex and heavy when in fact, it is simple, lightweight, and fast (doing no more than a simple dictionary lookup).
We could easily solve both problems with a helper function:
It would be used like this:
There was some discussion about a completely new decorator with different semantics (holding a lock across a call to an arbitrary user function and being limited to zero argument functions). It all the examples that were presented, this @cache decorator would suffice. None of examples presented actually locking behavior.
rhettinger commentedon May 8, 2020
FWIW, this doesn't preclude the other proposal if it ever gains traction and moves forward. This just takes existing functionality and improves clarity and discoverability.
The core issue is that if you only want a simple unbounded cache, it isn't obvious that that behavior is buried in the lru_cache() API. In hindsight, this always should have been separate functionality. And some day we may deprecate the maxsize=None option which is somewhat opaque.
rhettinger commentedon May 12, 2020
New changeset 21cdb71 by Raymond Hettinger in branch 'master':
bpo-40571: Make lru_cache(maxsize=None) more discoverable (GH-20019)
21cdb71
tasty0tomato commentedon Oct 25, 2024
I know it is really really late now. But we should really add this change to What’s New In Python 3.9 because it is actually an interesting and important new feature.