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