Issue 7848: copy.copy corrupts objects that return false value from getstate (original) (raw)
When copy.copy is used on an object whose getstate returns 0, it can produce a corrupt copy of an object:
import copy class Foo(object): ... def init(self): ... self.value = 0 ... def getstate(self): ... return self.value ... def setstate(self, v): ... self.value = v ... one = Foo() two = copy.copy(one) two.value Traceback (most recent call last): File "", line 1, in AttributeError: 'Foo' object has no attribute 'value'
Pickling/unpickling works fine for this object, so this appears to be a bug in copy._reconstruct.
This is not a contrived example, BTrees.Length.Length from ZODB uses such a getstate.