[issue38565] Expose the value passed of typed passed to functools.lru_cache
Serhiy Storchaka
report at bugs.python.org
Thu Oct 24 03:33:27 EDT 2019
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
It is easy:
diff --git a/Lib/functools.py b/Lib/functools.py
index 3192bd02d9..52c07db749 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -499,7 +499,9 @@ def lru_cache(maxsize=128, typed=False):
# The user_function was passed in directly via the maxsize argument
user_function, maxsize = maxsize, 128
wrapper = _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo)
- return update_wrapper(wrapper, user_function)
+ func = update_wrapper(wrapper, user_function)
+ func.cache_parameters = lambda: {'maxsize': maxsize, 'typed': typed}
+ return func
elif maxsize is not None:
raise TypeError(
'Expected first argument to be an integer, a callable, or None')
But there are many design questions. Why method instead of just attribute?
func.cache_parameters = {'maxsize': maxsize, 'typed': typed}
Or maybe just add the "typed" attribute?
func.typed = typed
Also I consider adding the more general "make_key" parameter to lru_cache(). The "typed" parameter would just specify the default value for "make_key".
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38565>
_______________________________________
More information about the Python-bugs-list
mailing list