deepcopy problem with new-style classes in Python 2.3a2

Stephen C Phillips news at scphillips.co.uk
Wed Mar 12 12:17:40 EST 2003


Hi,
	I am having a problem using deepcopy on a complex data structure.  I
think it can be distilled down to a basic difficulty shown below (thanks to
Jp Calderone).
	With Python 2.3a2 (or Python 2.2.2) I get this:

>>> class Foo(object):
...     pass
... 
>>> f = Foo()
>>> f.foo = f
>>> g = copy.deepcopy(f)
>>> g is not f
True
>>> f is f.foo
True
>>> g is g.foo
False

Obviously I would like "g.foo is foo" to be True.
g.foo is not f either, it is some other empty object.
With old-style classes I get the desired behaviour.  Can anyone explain
what the problem is?

Thanks.

Stephen Phillips.




More information about the Python-list mailing list