]> 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:32:55 +0000 (14:32 -0700)
committerGitHub <noreply@github.com>
Tue, 30 Mar 2021 21:32:55 +0000 (14:32 -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 341a3c7cd7660ce17e743e7c1f2e024d4f17e0c5..d41ff4fd077e65671bc05552c91931cd2be8d125 100644 (file)
@@ -314,6 +314,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 598b569ea958b8a8018b9fbca88b48360dd566dd..f8538dfb2b62d2a96e2f4fd2d6ec2352d8452cbd 100644 (file)
@@ -245,7 +245,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 e181c6171169e82c97328235533766ade8c4fa94..39aa954a7b449dd1ab9c619e11631f3590bd5111 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1334,6 +1334,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