]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-114737: Revert change to ElementTree.iterparse "root" attribute (GH-114755)
authorSam Gross <colesbury@gmail.com>
Wed, 31 Jan 2024 11:22:24 +0000 (06:22 -0500)
committerGitHub <noreply@github.com>
Wed, 31 Jan 2024 11:22:24 +0000 (13:22 +0200)
Prior to gh-114269, the iterator returned by ElementTree.iterparse was
initialized with the root attribute as None. This restores the previous
behavior.

Lib/test/test_xml_etree.py
Lib/xml/etree/ElementTree.py

index b9e7937b0bbc00a5163632269f3cc9e2e9d90272..221545b315fa44d1c25bb461920b698a7b1dd26c 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