Marian Ganisin <marian.gani...@gmail.com> added the comment:

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. :)

----------
keywords: +patch
nosy: +Marian.Ganisin
Added file: 
http://bugs.python.org/file22791/mganisin-Issue10131-Python-2.7.2.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10131>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to