-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
Option to make the lru_cache type specific #57436
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Based on a comment from Andrew Koenig, it is suggested that the lru_cache() offer an option to become type specific so that equal objects of different typed don't get cached to the same entry. Here's an example: @lru_cache(typed=True)
def square(x):
print('squaring', x)
return x * x
for x in [3, 3.0, 3, 3.0]:
print(square(x)) Without type specificity, all four calls will return 9 rather than 9. 9.0, 9, 9.0. First-pass patch attached. |
Updated patch to include tests and an application to the re module. |
The patch doesn't update the doc. You may also test type(square(3)). Except of these nits, the patch looks good. The typed option is an important feature, and your patch contains a good example of its usage (the re module). |
Features looks good, but the current patch doesn't handle keyword arguments correctly (more details in the Reitveld review). |
Nick, Ezio, and Victor, thanks for looking at the code.
|
Looks good to me (although it took me longer than it should have to figure out why you didn't need to store the keyword argument names a second time) |
New changeset cba503a2c468 by Raymond Hettinger in branch 'default': |
Victor, Ezio, and Nick, thanks for the review. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: