Skip to content

Commit 2636833

Browse files
bpo-33836: Recommend keyword-only param for memoization in FAQ (GH-7687)
Update the the signature in the code example to make `_cache` a keyword-only parameter. (cherry picked from commit 2707e41) Co-authored-by: Noah Haasis <haasis_noah@yahoo.de>
1 parent 9c6fe38 commit 2636833

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Doc/faq/programming.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ compute, a common technique is to cache the parameters and the resulting value
371371
of each call to the function, and return the cached value if the same value is
372372
requested again. This is called "memoizing", and can be implemented like this::
373373

374-
# Callers will never provide a third parameter for this function.
375-
def expensive(arg1, arg2, _cache={}):
374+
# Callers can only provide two parameters and optionally pass _cache by keyword
375+
def expensive(arg1, arg2, *, _cache={}):
376376
if (arg1, arg2) in _cache:
377377
return _cache[(arg1, arg2)]
378378

0 commit comments

Comments
 (0)