Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-36772 Allow lru_cache to be used as decorator without making a function call #13048

merged 5 commits into from May 26, 2019


Copy link

rhettinger commented May 2, 2019

Copy link

ericvsmith left a comment

Other than the one nit I noted, this looks good to me.

Doc/library/functools.rst Show resolved Hide resolved
Doc/library/functools.rst Outdated Show resolved Hide resolved
Lib/ Show resolved Hide resolved

This comment has been minimized.

Copy link

serhiy-storchaka commented May 2, 2019

To avoid misuse of the decorator, lru_cache should be treated as a decorator itself only if it is called with a single positional argument.

def lru_cache(*args, **kwargs):
    if not kwargs and len(args) == 1 and callable(args[0]):
        return lru_cache_impl()(args[0])
    return lru_cache_impl(*args, **kwargs)

lru_cache.__text_signature__ = '(maxsize=128, typed=False)'

def lru_cache_impl(maxsize=128, typed=False):
    ... # the current implementation
@rhettinger rhettinger merged commit b821868 into python:master May 26, 2019
5 checks passed
5 checks passed
Azure Pipelines PR #20190526.25 succeeded
bedevere/issue-number Issue number 36772 found
bedevere/news News entry found in Misc/NEWS.d
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
DinoV added a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
5 participants
You can’t perform that action at this time.