Skip to content

Commit 51a85dd

Browse files
authored
bpo-43399: Fix ElementTree.extend not working on iterators (pythonGH-24751)
1 parent 73b20ae commit 51a85dd

File tree

4 files changed

+7
-1
lines changed

4 files changed

+7
-1
lines changed

Lib/test/test_xml_etree.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,9 @@ def test_simpleops(self):
330330
elem.extend([e])
331331
self.serialize_check(elem, '<body><tag /><tag2 /></body>')
332332
elem.remove(e)
333+
elem.extend(iter([e]))
334+
self.serialize_check(elem, '<body><tag /><tag2 /></body>')
335+
elem.remove(e)
333336

334337
element = ET.Element("tag", key="value")
335338
self.serialize_check(element, '<tag key="value" />') # 1

Lib/xml/etree/ElementTree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def extend(self, elements):
252252
"""
253253
for element in elements:
254254
self._assert_is_element(element)
255-
self._children.extend(elements)
255+
self._children.append(element)
256256

257257
def insert(self, index, subelement):
258258
"""Insert *subelement* at position *index*."""

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,7 @@ Matheus Vieira Portela
13811381
Davin Potts
13821382
Guillaume Pratte
13831383
Florian Preinstorfer
1384+
Alex Prengère
13841385
Amrit Prem
13851386
Paul Prescod
13861387
Donovan Preston
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix ``ElementTree.extend`` not working on iterators when using the
2+
Python implementation

0 commit comments

Comments
 (0)