Skip to content

Conversation

@cfbolz
Copy link
Contributor

@cfbolz cfbolz commented Jan 19, 2026

The C version has this check, the Python version doesn't so far. This PR makes the behaviours agree again

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

nit :)

Co-authored-by: sobolevn <mail@sobolevn.me>
Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

LGTM

return decorating_function

def _lru_cache_wrapper(user_function, maxsize, typed, _CacheInfo):
if not callable(user_function):
Copy link
Member

@picnixz picnixz Jan 19, 2026

Choose a reason for hiding this comment

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

Can we move this check in lru_wrapper directly? it should only be done in def decorating_function() I think.

We are doing the check twice otherwise (when we do not call the decorator with ())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that means we are doing the "is it callable" already twice then. in practice, cpython never uses the pure python version of this code, and the "is it callable" check happens in the C version of _lru_cache_wrapper. my change is just mirroring what the C code is already doing.

unless there is a huge push for it, I kind of don't want to do a big refactoring of the C/Python code here.

Copy link
Member

Choose a reason for hiding this comment

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

There is no big refactoring actually. It is just about moving your check in another function (a few lines above). Considering the LRU wrapper cache function is already an implementation detail, I expect the caller to check for callability, not the wrapper itself.

…OK_gB.rst

Co-authored-by: AN Long <aisk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants