消息 [145976]
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. |
|
| 日期 |
用户 |
动作 |
参数 |
| 2011-10-19 22:06:36 | rhettinger | 修改 | recipients:
+ rhettinger |
| 2011-10-19 22:06:36 | rhettinger | 修改 | messageid: <1319061996.92.0.980251015091.issue13227@psf.upfronthosting.co.za> |
| 2011-10-19 22:06:36 | rhettinger | 链接 | issue13227 messages |
| 2011-10-19 22:06:36 | rhettinger | 创建 | |
|