[Python-bugs-list] [ python-Bugs-476616 ] UserDict.copy() error

noreply@sourceforge.net noreply@sourceforge.net
Tue, 30 Oct 2001 18:57:26 -0800


Bugs item #476616, was opened at 2001-10-30 18:57
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476616&group_id=5470

Category: Python Library
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: UserDict.copy() error

Initial Comment:
The copy() method applied to subclasses of UserDict
copies the object, but does not copy the contained
dictionary. The dictionary is shared between the
original and the copy.

The copy method applied to UserDict (not a subclass)
works okay.

This error goes back to at least 2.0, and still exists
in 2.2b1.

This little test program demonstrates the error:

----------------------------------------------
from UserDict import UserDict

class MyDict (UserDict):
	pass

d = MyDict()
d[1] = 11
c = d.copy()
c[2] = 22	# this should affect c only, but also affects
d
print "c:", c
print "d:", d
---------------------------------------

BTW, subclassing 'dictionary' works fine in 2.2 (of
course). For running under 2.0, I worked around this by
using copy.deepcopy().

I'm in no hurry for a fix for this.

Bob Alexander
balexander@rsv.ricoh.com

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=476616&group_id=5470