This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: lru_cache on 0-arity functions should default to maxsize=None
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Ehsonjon Gadoev, orf, remi.lapeyre, rhettinger, serhiy.storchaka
Priority: normal Keywords:

Created on 2020-07-11 22:46 by orf, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg373542 - (view) Author: Tom Forbes (orf) * Date: 2020-07-11 22:46
`functools.lru_cache` has a maxsize=128 default for all functions.

If a function has no arguments then this maxsize default is redundant and should be set to `maxsize=None`:

```
@functools.lru_cache()
def function_with_no_args():
    pass
```

Currently you need to add `maxsize=None` manually, and ensure that it is also updated if you alter the function to add arguments.
msg373544 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2020-07-11 23:34
Hi Tom Forbes, I don't think there is a way to be sure that's the function does not take any argument. Are you worried about the lost memory when maxsize is not set?
msg373545 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-07-12 01:10
The number of arguments is determined when the function is called (and it may be different for every call). maxsize is specified when the function is created.
msg373546 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-07-12 02:59
In 3.9, the @cache() alias is provided as a cleaner way to create an unbounded cache.¹  There is no need to special case a zero-arity function.  Besides as Rémi and Serhiy have pointed out, we can't know the arity in advance.

¹ https://docs.python.org/3.9/library/functools.html#functools.cache
History
Date User Action Args
2022-04-11 14:59:33adminsetgithub: 85452
2020-07-24 07:32:25serhiy.storchakasetpull_requests: - pull_request20743
2020-07-24 07:15:07Ehsonjon Gadoevsetnosy: + Ehsonjon Gadoev

pull_requests: + pull_request20743
2020-07-12 02:59:16rhettingersetstatus: open -> closed
resolution: out of date
messages: + msg373546

stage: resolved
2020-07-12 02:43:24xtreaksetnosy: + rhettinger
2020-07-12 01:10:29serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg373545
2020-07-11 23:34:58remi.lapeyresetnosy: + remi.lapeyre
messages: + msg373544
2020-07-11 22:46:12orfcreate