bpo-33836: Recommend keyword-only param for memoization in FAQ (GH-7687)
authorNoah Haasis <haasis_noah@yahoo.de>
Sat, 16 Jun 2018 03:29:11 +0000 (05:29 +0200)
committerMariatta <Mariatta@users.noreply.github.com>
Sat, 16 Jun 2018 03:29:11 +0000 (20:29 -0700)
Update the the signature in the code example to make `_cache` a keyword-only parameter.

Doc/faq/programming.rst

index d986ab642bfb32a6fe8fdb91cd8d0554814070a5..53f3b7f528c065e746ea3151a94b9f291f96b4ad 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)]