[issue35300] Bug with memoization and mutable objects
STINNER Victor
report at bugs.python.org
Fri Nov 23 07:15:29 EST 2018
STINNER Victor <vstinner at redhat.com> added the comment:
> 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.
It would be inefficient to deep copy the mutable result and can defeat the purpose of the cache...
I would rather to add a note to the documentation to explain to either not return mutable objects or to not modify them :-)
https://docs.python.org/dev/library/functools.html#functools.lru_cache
----------
nosy: +rhettinger, vstinner
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35300>
_______________________________________
More information about the Python-bugs-list
mailing list