]> granicus.if.org Git - python/commitdiff
bpo-33836: Recommend keyword-only param for memoization in FAQ (GH-7687)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 16 Jun 2018 03:50:28 +0000 (20:50 -0700)
committerGitHub <noreply@github.com>
Sat, 16 Jun 2018 03:50:28 +0000 (20:50 -0700)
Update the the signature in the code example to make `_cache` a keyword-only parameter.
(cherry picked from commit 2707e41a5c7ede30349cc7dbd66f8be564965d7c)

Co-authored-by: Noah Haasis <haasis_noah@yahoo.de>
Doc/faq/programming.rst

index 7476ce11f4f141189e241ddb22640d67b1173468..b717ab8f0f81ef2246509639f4b7673e92d57a3e 100644 (file)
@@ -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)]