Author bolorsociedad
Recipients bolorsociedad
Date 2018-11-23.11:53:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1542973998.98.0.788709270274.issue35300@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-11-23 11:53:19bolorsociedadsetrecipients: + bolorsociedad
2018-11-23 11:53:18bolorsociedadsetmessageid: <1542973998.98.0.788709270274.issue35300@psf.upfronthosting.co.za>
2018-11-23 11:53:18bolorsociedadlinkissue35300 messages
2018-11-23 11:53:18bolorsociedadcreate