Message145976
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. |
|
Date |
User |
Action |
Args |
2011-10-19 22:06:36 | rhettinger | set | recipients:
+ rhettinger |
2011-10-19 22:06:36 | rhettinger | set | messageid: <1319061996.92.0.980251015091.issue13227@psf.upfronthosting.co.za> |
2011-10-19 22:06:36 | rhettinger | link | issue13227 messages |
2011-10-19 22:06:36 | rhettinger | create | |
|