You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
improper use of __setitem__ in ElementTree for Python 3.1 #50814
bpo-6472: Update ElementTree with upstream changes
Files
test.py: Test file showing the behaviour described.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2010-03-11.14:57:27.228>created_at=<Date2009-07-24.19:46:51.533>labels= ['expert-XML', 'type-bug']
title='improper use of __setitem__ in ElementTree for Python 3.1'updated_at=<Date2010-03-11.14:57:27.226>user='https://github.com/aroberge'
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:
defreplace_element(elem, replacement):
'''replace the content of an ElementTree Element by that ofanother one. '''elem.clear()
elem.text=replacement.textelem.tail=replacement.tailelem.tag=replacement.tagelem.attrib=replacement.attribtry:
elem[:] =replacement[:] # works with Python 2.5 but not 3.1exceptAssertionError:
delelem[:]
forchildinreplacement:
elem.append(child)
I have included a small test file which demonstrate the behaviour.
Activity
aroberge commentedon Jul 24, 2009
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:
I have included a small test file which demonstrate the behaviour.
florentx commentedon Feb 16, 2010
Should be fixed with the upstream version, proposed on bpo-6472.
florentx commentedon Mar 11, 2010
Fixed in 2.7 with bpo-6472. It should be ported to 3.x later.