[issue25447] TypeError invoking deepcopy on lru_cache

Jason R. Coombs report at bugs.python.org
Tue Oct 20 17:14:41 EDT 2015


Jason R. Coombs added the comment:

Indeed. I guess my point about "supported" related to not having tests capturing this requirement or docs stipulating it.

My instinct on the latter question is this - an lru_cache-decorated function is a stateful function. It is mutable, much like a dict or list. If simply copied, the resulting function should have references to the same state. If _deep_ copied, the state (cache) should be similarly deep copied.

Focusing on the deep copy operation, if a cached function is copied, the copy could have additional operations invoked on it and its cache would hit or miss on those calls independently from the original function, and likewise subsequent calls on the original function should not hit on calls unique to the copied function.

I don't have a heavy investment in this expectation. It's also reasonable to me that a deepcopy operation could reuse the same cache or result in an uninitialized one.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25447>
_______________________________________


More information about the Python-bugs-list mailing list