]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-43399: Fix ElementTree.extend not working on iterators (GH-24751)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 30 Mar 2021 21:36:25 +0000 (14:36 -0700)
committerGitHub <noreply@github.com>
Tue, 30 Mar 2021 21:36:25 +0000 (14:36 -0700)
(cherry picked from commit 51a85ddce8b336addcb61b96f04c9c5edef07296)

Co-authored-by: Alex Prengère <2138730+alexprengere@users.noreply.github.com>
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py
Misc/ACKS
Misc/NEWS.d/next/Library/2021-03-04-17-53-46.bpo-43399.Wn95u-.rst [new file with mode: 0644]

index 5632b8b503cf3f9d92c80223da0362ff431a466a..bfc0d054ba8b73860eca3e3bb4e28cf1aa671d3f 100644 (file)
@@ -312,6 +312,9 @@ class ElementTreeTest(unittest.TestCase):
         elem.extend([e])
         self.serialize_check(elem, '<body><tag /><tag2 /></body>')
         elem.remove(e)
+        elem.extend(iter([e]))
+        self.serialize_check(elem, '<body><tag /><tag2 /></body>')
+        elem.remove(e)
 
         element = ET.Element("tag", key="value")
         self.serialize_check(element, '<tag key="value" />') # 1
index 7a269001d6e18f60790f5565d69b301622139469..ac82ed8041995dbb667c8c15c3573a8889038bcf 100644 (file)
@@ -252,7 +252,7 @@ class Element:
         """
         for element in elements:
             self._assert_is_element(element)
-        self._children.extend(elements)
+            self._children.append(element)
 
     def insert(self, index, subelement):
         """Insert *subelement* at position *index*."""
index 73d35c2d86bdc01d1b110360ae536906ba6aeffe..4f7c92c9dc0f6adeb5b8f5b524810888be624fb9 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1363,6 +1363,7 @@ Matheus Vieira Portela
 Davin Potts
 Guillaume Pratte
 Florian Preinstorfer
+Alex Prengère
 Amrit Prem
 Paul Prescod
 Donovan Preston
diff --git a/Misc/NEWS.d/next/Library/2021-03-04-17-53-46.bpo-43399.Wn95u-.rst b/Misc/NEWS.d/next/Library/2021-03-04-17-53-46.bpo-43399.Wn95u-.rst
new file mode 100644 (file)
index 0000000..0b8dffb
--- /dev/null
@@ -0,0 +1,2 @@
+Fix ``ElementTree.extend`` not working on iterators when using the
+Python implementation