Skip to content

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

Merged
rhettinger merged 5 commits intopython:masterfrom
rhettinger:lru_no_args
May 26, 2019
Merged

bpo-36772 Allow lru_cache to be used as decorator without making a function call#13048
rhettinger merged 5 commits intopython:masterfrom
rhettinger:lru_no_args

Conversation

@rhettinger
Copy link
Copy Markdown
Contributor

@rhettinger rhettinger commented May 2, 2019

Copy link
Copy Markdown
Member

@ericvsmith ericvsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread Misc/NEWS.d/next/Library/2019-05-01-20-41-53.bpo-36772.fV2K0F.rst Outdated
Comment thread Doc/library/functools.rst
Comment thread Doc/library/functools.rst Outdated
Comment thread Lib/functools.py
@serhiy-storchaka
Copy link
Copy Markdown
Member

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
DinoV pushed 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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants