Author jaraco
Recipients jaraco, rhettinger
Date 2015-10-20.16:32:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Beginning with Python 3.5, an lru_cache no longer survives a deepcopy.

$ cat >>
import copy
from functools import lru_cache
foo = lru_cache()(lambda: None)
$ python3.5
Traceback (most recent call last):
  File "", line 4, in <module>
  File "/usr/lib/python3.5/", line 182, in deepcopy
    y = _reconstruct(x, rv, 1, memo)
  File "/usr/lib/python3.5/", line 293, in _reconstruct
    y = callable(*args)
  File "/usr/lib/python3.5/", line 88, in __newobj__
    return cls.__new__(cls, *args)
TypeError: Required argument 'user_function' (pos 1) not found

I suspect this is due to the C implementation per issue14373.

I realize one's first reaction might be "why are you deep copying a function," so here's the [downstream bug]( and [offended code]( That decorator is designed to wrap a method and to store the cache on the instance object, an object which is liable to be deep copied. As a result, production code using this technique is failing on Python 3.5.

Although it was apparently an artifact of previous implementations that the cache happened to be deep-copyable, I hope this expectation can be restored with minimal fuss.
Date User Action Args
2015-10-20 16:32:09jaracosetrecipients: + jaraco, rhettinger
2015-10-20 16:32:09jaracosetmessageid: <>
2015-10-20 16:32:09jaracolinkissue25447 messages
2015-10-20 16:32:08jaracocreate