]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-114737: Revert change to ElementTree.iterparse "root" attribute (GH-114755...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 31 Jan 2024 11:59:58 +0000 (12:59 +0100)
committerGitHub <noreply@github.com>
Wed, 31 Jan 2024 11:59:58 +0000 (11:59 +0000)
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 <colesbury@gmail.com>
Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py

index 53a4e9f821d6dd119a3466e20ce494b93e332b07..b50898f1d18b581f7384490d028d74f029453b1b 100644 (file)
@@ -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'),
index ae6575028be11cbe8fed8d1a1f8d0fe4db12df12..bb7362d1634a72649269b65648a9777d9c763de6 100644 (file)
@@ -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