Issue 4712: Document pickle behavior for subclasses of dicts/lists (original) (raw)

The copy module uses the same reduce protocol, but reconstruct the object in different order, first set state, then add items. This discrepancy causes a difference between results of pickle/unpickle and copy operations. Example:

class L(list): ... def getstate(self): ... return list(self) ... def setstate(self, state): ... self[:] = state ... import copy, pickle pickle.loads(pickle.dumps(L([1, 2]))) [1, 2] copy.deepcopy(L([1, 2])) [1, 2, 1, 2]

This was happened with xml.dom.minicompat.NodeList ().

Definitely one of pickle's or copy's behavior should be changed. But what?