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.

classification
Title: improper use of __setitem__ in ElementTree for Python 3.1
Type: behavior Stage: resolved
Components: XML Versions: Python 3.1, Python 3.2
process
Status: closed Resolution: fixed
Dependencies: Superseder: Update ElementTree with upstream changes
View: 6472
Assigned To: effbot Nosy List: aroberge, effbot, flox
Priority: high Keywords:

Created on 2009-07-24 19:46 by aroberge, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test.py aroberge, 2009-07-24 19:46 Test file showing the behaviour described.
Messages (3)
msg90891 - (view) Author: Andre Roberge (aroberge) * Date: 2009-07-24 19:46
I have a function to replace the content of an ElementTree Element by
that of another one which works using Python 2 but not with Python 3.
I get an assertion error.  

It was suggested on the Python list that the problem is that in Python 3
slice assignments are done with __setitem__ rather than __setslice__ but
ElementTree has not been adapted to that -- hence the title given to
this bug.

The function that I use to demonstrate this (with a workaround solution)
is as follows:

def replace_element(elem, replacement):
    '''replace the content of an ElementTree Element by that of
another
       one.
    '''
    elem.clear()
    elem.text = replacement.text
    elem.tail = replacement.tail
    elem.tag = replacement.tag
    elem.attrib = replacement.attrib
    try:
        elem[:] = replacement[:]  # works with Python 2.5 but not 3.1
    except AssertionError:
        del elem[:]
        for child in replacement:
            elem.append(child)

I have included a small test file which demonstrate the behaviour.
msg99398 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-02-16 12:13
Should be fixed with the upstream version, proposed on #6472.
msg100863 - (view) Author: Florent Xicluna (flox) * (Python committer) Date: 2010-03-11 14:57
Fixed in 2.7 with #6472. It should be ported to 3.x later.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50814
2010-03-11 14:57:27floxsetstatus: open -> closed
superseder: Update ElementTree with upstream changes
messages: + msg100863

dependencies: - Update ElementTree with upstream changes
resolution: fixed
stage: needs patch -> resolved
2010-02-16 12:13:29floxsetnosy: + flox
messages: + msg99398

dependencies: + Update ElementTree with upstream changes
components: + XML, - Library (Lib)
2009-07-25 17:20:53pitrousetversions: + Python 3.2
nosy: + effbot

priority: high
assignee: effbot
stage: needs patch
2009-07-24 19:46:51arobergecreate