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.

Author Marian.Ganisin
Recipients Marian.Ganisin, flox
Date 2011-07-29.09:08:20
SpamBayes Score 3.98803e-12
Marked as misclassified No
Message-id <>
xml.dom.minicompat.NodeList provides __reduce__/__reduce_ex__ methods, they return "state" as well as "list iterator". However one of those seems to be absolutely enough for reconstruction of instance (__reduce__/__reduce_ex__ are inherited, methods __setstate/__getstate__ aka state provider/consumer are defined in NodeList).

deepcopy (actually its helper function _reconstruct) uses both, state and list iterator for copying, first it calls __setstate__(state) on new copy, then it goes through iterator and calls append(item) (as it is probably common for lists). This is it! (state and list iterator contain same information, list of items)

Prior to some minor 2.7 update deepcopy used list iterator and state in opposite order, first it run append through iterator, then __setstate__ (this overwrote new content at all, no unwanted copies appeared). So the issue is there all the time, just with no impact in the past.

Issue also occurs with simple copy.copy() on NodeList:

>>> import copy
>>> from xml.dom import minidom
>>> doc = minidom.parseString('<root/>')
>>> print copy.copy(doc.childNodes)
[<DOM Element: root at 0xb73fbbcc>, <DOM Element: root at 0xb73fbbcc>]

I am strongly convinced NodeList doesn't require __setstate__/__getstate__ methods (even more I believe they are not desired in subclass of list). Therefore I am proposing patch with removal of these methods.

If I am wrong in my final decision, somebody smarter has to find a solution. This is the reason why I described issue in deep. :)
Date User Action Args
2011-07-29 09:08:22Marian.Ganisinsetrecipients: + Marian.Ganisin, flox
2011-07-29 09:08:21Marian.Ganisinsetmessageid: <>
2011-07-29 09:08:21Marian.Ganisinlinkissue10131 messages
2011-07-29 09:08:20Marian.Ganisincreate