[New-bugs-announce] [issue6565] improper use of __setitem__ in ElementTree for Python 3.1
Andre Roberge
report at bugs.python.org
Fri Jul 24 21:46:53 CEST 2009
New submission from Andre Roberge <andre.roberge at gmail.com>:
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.
----------
components: Library (Lib)
files: test.py
messages: 90891
nosy: aroberge
severity: normal
status: open
title: improper use of __setitem__ in ElementTree for Python 3.1
type: behavior
versions: Python 3.1
Added file: http://bugs.python.org/file14560/test.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6565>
_______________________________________
More information about the New-bugs-announce
mailing list