[Twisted-Python] copy.deepcopy domish.Element works in python 2.5 but not in 2.6
Hello everyone, for some reason copy.deepcopy forks great on a domish.Element on 2.5 but not in 2.6 : Python 2.5.4 (r254:67916, Sep 20 2009, 10:05:43) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
from twisted.words.xish import domish import copy msg = domish.Element(('jabber:client', 'message')) msg2 = copy.deepcopy(msg)
Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
from twisted.words.xish import domish import copy msg = domish.Element(('jabber:client', 'message')) msg2 = copy.deepcopy(msg) Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.AttributeError'> ignored
does someone understand why? I'm using twisted 8.2 on ubuntu 9.10. Thank you, Gabriel
On 05:40 pm, gabriel.rossetti@arimaz.com wrote:
Hello everyone,
for some reason copy.deepcopy forks great on a domish.Element on 2.5 but not in 2.6 :
Python 2.5.4 (r254:67916, Sep 20 2009, 10:05:43) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
from twisted.words.xish import domish import copy msg = domish.Element(('jabber:client', 'message')) msg2 = copy.deepcopy(msg)
Python 2.6.4 (r264:75706, Nov 2 2009, 14:38:03) [GCC 4.4.1] on linux2 Type "help", "copyright", "credits" or "license" for more information.
from twisted.words.xish import domish import copy msg = domish.Element(('jabber:client', 'message')) msg2 = copy.deepcopy(msg) Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <type 'exceptions.AttributeError'> ignored
does someone understand why? I'm using twisted 8.2 on ubuntu 9.10. Thank you, Gabriel
Actually, it looks like it works about equally well on either version. While it looks like an exception was raised by deepcopy on Python 2.6, notice that the exception was actually *ignored*. You get back a copy, and it even seems to have all the right attributes. ;) The infinite recursion in deepcopy happens on Python 2.5 as well. I'm not completely sure why it's not being reported, but it probably has to do with tiny differences in how deepcopy works. hasattr is well known for swallowing exceptions silently. The impressive thing is that the error is reported at all in Python 2.6. A good rule of thumb is to assume that types don't support being copied like this unless their docs explicitly state that they do. If you want this to be supported, it's probably not too hard to implement. Feel free to file a ticket with a patch. :) Jean-Paul
On Thu, 2009-12-17 at 18:11 +0000, exarkun@twistedmatrix.com wrote:
On 05:40 pm, gabriel.rossetti@arimaz.com wrote:
Hello everyone,
for some reason copy.deepcopy forks great on a domish.Element on 2.5 but not in 2.6 :
Actually, it looks like it works about equally well on either version. While it looks like an exception was raised by deepcopy on Python 2.6, notice that the exception was actually *ignored*. You get back a copy, and it even seems to have all the right attributes. ;)
The infinite recursion in deepcopy happens on Python 2.5 as well. I'm not completely sure why it's not being reported, but it probably has to do with tiny differences in how deepcopy works. hasattr is well known for swallowing exceptions silently. The impressive thing is that the error is reported at all in Python 2.6.
A good rule of thumb is to assume that types don't support being copied like this unless their docs explicitly state that they do. If you want this to be supported, it's probably not too hard to implement. Feel free to file a ticket with a patch. :)
There is an open ticket about this: http://twistedmatrix.com/trac/ticket/724 In short: it is probably a bad idea, and I'm curious about the possible useful use cases. ralphm
participants (3)
-
exarkun@twistedmatrix.com
-
Gabriel Rossetti
-
Ralph Meijer