@@ -76,7 +76,8 @@ The :mod:`functools` module defines the following functions:
7676 .. versionadded :: 3.2
7777
7878
79- .. decorator :: lru_cache(maxsize=128, typed=False)
79+ .. decorator :: lru_cache(user_function)
80+ lru_cache(maxsize=128, typed=False)
8081
8182 Decorator to wrap a function with a memoizing callable that saves up to the
8283 *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:
9091 differ in their keyword argument order and may have two separate cache
9192 entries.
9293
94+ If *user_function * is specified, it must be a callable. This allows the
95+ *lru_cache * decorator to be applied directly to a user function, leaving
96+ the *maxsize * at its default value of 128::
97+
98+ @lru_cache
99+ def count_vowels(sentence):
100+ sentence = sentence.casefold()
101+ return sum(sentence.count(vowel) for vowel in 'aeiou')
102+
93103 If *maxsize * is set to ``None ``, the LRU feature is disabled and the cache can
94104 grow without bound. The LRU feature performs best when *maxsize * is a
95105 power-of-two.
@@ -165,6 +175,9 @@ The :mod:`functools` module defines the following functions:
165175 .. versionchanged :: 3.3
166176 Added the *typed * option.
167177
178+ .. versionchanged :: 3.8
179+ Added the *user_function * option.
180+
168181.. decorator :: total_ordering
169182
170183 Given a class defining one or more rich comparison ordering methods, this
0 commit comments