Issue 1099746: copy.deepcopy barfs when copying a class derived from dict (original) (raw)

I've got a class:

class odict(dict):

def init(self, d={}): self._keys = d.keys() dict.init(self, d)

def setitem(self, key, item): dict.setitem(self, key, item) if key not in self._keys: self._keys.append(key)

...

When I copy.deepcopy one of these it blows up in setitem with an AttributeError on _keys, because setitem is called without init ever having been called. Presumably this thing looks and smells like a dictionary, so deepcopy thinks it is one.