This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: copy.deepcopy barfs when copying a class derived from dict
Type: Stage:
Components: Library (Lib) Versions: Python 2.3
Status: closed Resolution: duplicate
Dependencies: Superseder: deepcopying listlike and dictlike objects
View: 1100562
Assigned To: Nosy List: sonderblade, winjer
Priority: normal Keywords:

Created on 2005-01-10 21:28 by winjer, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg60629 - (view) Author: Doug Winter (winjer) Date: 2005-01-10 21:28
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:


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.
msg60630 - (view) Author: Björn Lindqvist (sonderblade) Date: 2005-01-15 02:58
Logged In: YES 

See patch 1100562
Date User Action Args
2022-04-11 14:56:09adminsetgithub: 41420
2008-01-20 19:30:38christian.heimessetstatus: open -> closed
resolution: duplicate
superseder: deepcopying listlike and dictlike objects
2005-01-10 21:28:19winjercreate