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

@@ -0,0 +1,3 @@
The Python implementation of :func:`functools.lru_cache` differed from the
default C implementation in that it did not check that its argument is
callable. This discrepancy is now fixed and both raise a :class:`TypeError`.
Copy link
Contributor

@aisk aisk Jan 19, 2026

Choose a reason for hiding this comment

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

More specifically:

Suggested change
callable. This discrepancy is now fixed and both raise a :class:`TypeError`.
callable. This discrepancy is now fixed and both raise a :exc:`TypeError`.

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 ())

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