[issue41220] add optional make_key argument to lru_cache

Raymond Hettinger report at bugs.python.org
Mon Jul 6 19:47:44 EDT 2020


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

>>> from functools import lru_cache
>>> def my_make_key(my_list):
...   return my_list[0]
...
>>> @lru_cache(128, make_key=my_make_key)
... def cached_func(my_list):
...   return sum(my_list)
...
>>> cached_func([10, 20, 30])
60
>>> cached_func([10, 11, 12]) # <-- Why would we want this to return 60?
60

This seems unsafe.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41220>
_______________________________________


More information about the Python-bugs-list mailing list