Message330309
The decorator functools.lru_cache seems to not work properly when the function to be memoized returns a mutable object.
For instance:
>>> import functools
>>> @functools.lru_cache()
... def f(x):
... return [x, x + 1]
...
>>> a = f(4)
>>> print(a)
[4, 5]
>>> a[0] = 0
>>> f(4)
[0, 5]
When the returned mutable object is modified, the cache is modified as well. In my opinion, functools.lru_cache should store a deep copy of the returned object. |
|
Date |
User |
Action |
Args |
2018-11-23 11:53:19 | bolorsociedad | set | recipients:
+ bolorsociedad |
2018-11-23 11:53:18 | bolorsociedad | set | messageid: <1542973998.98.0.788709270274.issue35300@psf.upfronthosting.co.za> |
2018-11-23 11:53:18 | bolorsociedad | link | issue35300 messages |
2018-11-23 11:53:18 | bolorsociedad | create | |
|