[Python-checkins] bpo-43399: Fix ElementTree.extend not working on iterators (GH-24751)

miss-islington webhook-mailer at python.org
Tue Mar 30 17:36:34 EDT 2021


https://github.com/python/cpython/commit/b500bd8e672d15c6dfa24568a3264fdc0f3e0c01
commit: b500bd8e672d15c6dfa24568a3264fdc0f3e0c01
branch: 3.9
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2021-03-30T14:36:25-07:00
summary:

bpo-43399: Fix ElementTree.extend not working on iterators (GH-24751)

(cherry picked from commit 51a85ddce8b336addcb61b96f04c9c5edef07296)

Co-authored-by: Alex Prengère <2138730+alexprengere at users.noreply.github.com>

files:
A Misc/NEWS.d/next/Library/2021-03-04-17-53-46.bpo-43399.Wn95u-.rst
M Lib/test/test_xml_etree.py
M Lib/xml/etree/ElementTree.py
M Misc/ACKS

diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 5632b8b503cf3..bfc0d054ba8b7 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -312,6 +312,9 @@ def test_simpleops(self):
         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
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 7a269001d6e18..ac82ed8041995 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -252,7 +252,7 @@ def extend(self, elements):
         """
         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*."""
diff --git a/Misc/ACKS b/Misc/ACKS
index 73d35c2d86bdc..4f7c92c9dc0f6 100644
--- 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
index 0000000000000..0b8dffb2312e4
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2021-03-04-17-53-46.bpo-43399.Wn95u-.rst
@@ -0,0 +1,2 @@
+Fix ``ElementTree.extend`` not working on iterators when using the
+Python implementation



More information about the Python-checkins mailing list