From 734ba67a1c250eaed1d3393c703e7b4951250f0c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alex=20Preng=C3=A8re?=
<2138730+alexprengere@users.noreply.github.com>
Date: Tue, 30 Mar 2021 23:11:29 +0200
Subject: [PATCH] bpo-43399: Fix ElementTree.extend not working on iterators
(GH-24751) (cherry picked from commit
51a85ddce8b336addcb61b96f04c9c5edef07296)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Co-authored-by: Alex Prengère <2138730+alexprengere@users.noreply.github.com>
---
Lib/test/test_xml_etree.py | 3 +++
Lib/xml/etree/ElementTree.py | 2 +-
Misc/ACKS | 1 +
.../next/Library/2021-03-04-17-53-46.bpo-43399.Wn95u-.rst | 2 ++
4 files changed, 7 insertions(+), 1 deletion(-)
create mode 100644 Misc/NEWS.d/next/Library/2021-03-04-17-53-46.bpo-43399.Wn95u-.rst
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 341a3c7cd7660c..d41ff4fd077e65 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -314,6 +314,9 @@ def test_simpleops(self):
elem.extend([e])
self.serialize_check(elem, '
')
elem.remove(e)
+ elem.extend(iter([e]))
+ self.serialize_check(elem, '')
+ elem.remove(e)
element = ET.Element("tag", key="value")
self.serialize_check(element, '') # 1
diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py
index 598b569ea958b8..f8538dfb2b62d2 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -245,7 +245,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 e181c6171169e8..39aa954a7b449d 100644
--- 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
index 00000000000000..0b8dffb2312e4f
--- /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