https://github.com/python/cpython/commit/3982049a3054b0503b09d9b9d2a1735a3195048c
commit: 3982049a3054b0503b09d9b9d2a1735a3195048c
branch: 3.11
author: Miss Islington (bot) <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-01-31T12:03:08Z
summary:

[3.11] gh-114737: Revert change to ElementTree.iterparse "root" attribute 
(GH-114755) (GH-114799)

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 <[email protected]>

files:
M Lib/test/test_xml_etree.py
M Lib/xml/etree/ElementTree.py

diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
index 57f5de34fdc108..267982a8233c92 100644
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -536,7 +536,9 @@ def test_iterparse(self):
         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 d4b259e31a7de7..fce0c2963a28d5 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1271,8 +1271,8 @@ def __del__(self):
                 source.close()
 
     it = IterParseIterator()
+    it.root = None
     wr = weakref.ref(it)
-    del IterParseIterator
     return it
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to