Issue6565
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) * ![]() |
Date: 2010-02-16 12:13 | |
Should be fixed with the upstream version, proposed on #6472. |
|||
| msg100863 - (view) | Author: Florent Xicluna (flox) * ![]() |
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:51 | admin | set | github: 50814 |
| 2010-03-11 14:57:27 | flox | set | status: open -> closed superseder: Update ElementTree with upstream changes messages: + msg100863 dependencies:
- Update ElementTree with upstream changes |
| 2010-02-16 12:13:29 | flox | set | nosy:
+ flox messages: + msg99398 dependencies:
+ Update ElementTree with upstream changes |
| 2009-07-25 17:20:53 | pitrou | set | versions:
+ Python 3.2 nosy: + effbot priority: high |
| 2009-07-24 19:46:51 | aroberge | create | |
