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 2707e41a5c)

Co-authored-by: Noah Haasis <haasis_noah@yahoo.de>
This commit is contained in:
Miss Islington (bot) 2018-06-15 20:46:30 -07:00 committed by GitHub
parent 18793e1f60
commit 5a0bf74d4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

View 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)]