From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 31 Jan 2024 11:59:58 +0000 (+0100) Subject: [3.12] gh-114737: Revert change to ElementTree.iterparse "root" attribute (GH-114755... X-Git-Tag: v3.12.2~56 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5d7b90db0cd463e69d15acf5498232b9bc2bfeaa;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-114737: Revert change to ElementTree.iterparse "root" attribute (GH-114755) (GH-114798) Prior to gh-114269, the iterator returned by ElementTree.iterparse was initialized with the root attribute as None. This restores the previous behavior. (cherry picked from commit 66f95ea6a65deff547cab0d312b8c8c8a4cf8beb) Co-authored-by: Sam Gross --- diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 53a4e9f821d6..b50898f1d18b 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -536,7 +536,9 @@ class ElementTreeTest(unittest.TestCase): iterparse = ET.iterparse context = iterparse(SIMPLE_XMLFILE) + self.assertIsNone(context.root) action, elem = next(context) + self.assertIsNone(context.root) self.assertEqual((action, elem.tag), ('end', 'element')) self.assertEqual([(action, elem.tag) for action, elem in context], [ ('end', 'element'), diff --git a/Lib/xml/etree/ElementTree.py b/Lib/xml/etree/ElementTree.py index ae6575028be1..bb7362d1634a 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1256,8 +1256,8 @@ def iterparse(source, events=None, parser=None): source.close() it = IterParseIterator() + it.root = None wr = weakref.ref(it) - del IterParseIterator return it