summaryrefslogtreecommitdiffstats
path: root/Doc/faq
diff options
context:
space:
mode:
authorNoah Haasis <haasis_noah@yahoo.de>2018-06-16 03:29:11 (GMT)
committerMariatta <Mariatta@users.noreply.github.com>2018-06-16 03:29:11 (GMT)
commit2707e41a5c7ede30349cc7dbd66f8be564965d7c (patch)
tree52b83352eaa4a4cca1a1c9b46414954ac33ab1cd /Doc/faq
parent7469ff5017ec315a81e35913f19a32f0dbdf712e (diff)
downloadcpython-2707e41a5c7ede30349cc7dbd66f8be564965d7c.zip
cpython-2707e41a5c7ede30349cc7dbd66f8be564965d7c.tar.gz
cpython-2707e41a5c7ede30349cc7dbd66f8be564965d7c.tar.bz2
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.
Diffstat (limited to 'Doc/faq')
-rw-r--r--Doc/faq/programming.rst4
1 files changed, 2 insertions, 2 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index d986ab6..53f3b7f 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -371,8 +371,8 @@ compute, a common technique is to cache the parameters and the resulting value
of each call to the function, and return the cached value if the same value is
requested again. This is called "memoizing", and can be implemented like this::
- # Callers will never provide a third parameter for this function.
- def expensive(arg1, arg2, _cache={}):
+ # Callers can only provide two parameters and optionally pass _cache by keyword
+ def expensive(arg1, arg2, *, _cache={}):
if (arg1, arg2) in _cache:
return _cache[(arg1, arg2)]