summaryrefslogtreecommitdiffstats
path: root/Doc/library/functools.rst
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/library/functools.rst')
-rw-r--r--Doc/library/functools.rst15
1 files changed, 14 insertions, 1 deletions
diff --git a/Doc/library/functools.rst b/Doc/library/functools.rst
index 16a779f..8b8b1f8 100644
--- a/Doc/library/functools.rst
+++ b/Doc/library/functools.rst
@@ -76,7 +76,8 @@ The :mod:`functools` module defines the following functions:
.. versionadded:: 3.2
-.. decorator:: lru_cache(maxsize=128, typed=False)
+.. decorator:: lru_cache(user_function)
+ lru_cache(maxsize=128, typed=False)
Decorator to wrap a function with a memoizing callable that saves up to the
*maxsize* most recent calls. It can save time when an expensive or I/O bound
@@ -90,6 +91,15 @@ The :mod:`functools` module defines the following functions:
differ in their keyword argument order and may have two separate cache
entries.
+ If *user_function* is specified, it must be a callable. This allows the
+ *lru_cache* decorator to be applied directly to a user function, leaving
+ the *maxsize* at its default value of 128::
+
+ @lru_cache
+ def count_vowels(sentence):
+ sentence = sentence.casefold()
+ return sum(sentence.count(vowel) for vowel in 'aeiou')
+
If *maxsize* is set to ``None``, the LRU feature is disabled and the cache can
grow without bound. The LRU feature performs best when *maxsize* is a
power-of-two.
@@ -165,6 +175,9 @@ The :mod:`functools` module defines the following functions:
.. versionchanged:: 3.3
Added the *typed* option.
+ .. versionchanged:: 3.8
+ Added the *user_function* option.
+
.. decorator:: total_ordering
Given a class defining one or more rich comparison ordering methods, this