-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-144030: add check that argument is callable to Python version of functools.lru_cache #144031
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
base: main
Are you sure you want to change the base?
gh-144030: add check that argument is callable to Python version of functools.lru_cache #144031
Conversation
sobolevn
left a comment
There was a problem hiding this 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>
vstinner
left a comment
There was a problem hiding this 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`. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More specifically:
| 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): |
There was a problem hiding this comment.
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 ())
The C version has this check, the Python version doesn't so far. This PR makes the behaviours agree again
functools.lru_cachedoes not check that argument is callable #144030