[New-bugs-announce] [issue41220] add optional make_key argument to lru_cache

Itay azolay report at bugs.python.org
Mon Jul 6 12:51:10 EDT 2020


New submission from Itay azolay <itayazolay at gmail.com>:

I'd like to add optional argument to lru_cache.
This argument is a user given function that will replace the default behaviour of creating a key from the args/kwds of the function.

for example:

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)

This will creating a cached function that accepts immutable.
Also, It will allow user to add custom functions from knowledge about the expected function input, without the need to create custom classes and/or overriding __hash__

----------
components: Library (Lib)
messages: 373141
nosy: Itayazolay
priority: normal
severity: normal
status: open
title: add optional make_key argument to lru_cache
type: enhancement
versions: Python 3.10

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


More information about the New-bugs-announce mailing list