https://github.com/python/cpython/commit/66f95ea6a65deff547cab0d312b8c8c8a4cf8beb
commit: 66f95ea6a65deff547cab0d312b8c8c8a4cf8beb
branch: main
author: Sam Gross <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-01-31T13:22:24+02:00
summary:

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

Prior to gh-114269, the iterator returned by ElementTree.iterparse was
initialized with the root attribute as None. This restores the previous
behavior.

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 b9e7937b0bbc00..221545b315fa44 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 ae6575028be11c..bb7362d1634a72 100644
--- a/Lib/xml/etree/ElementTree.py
+++ b/Lib/xml/etree/ElementTree.py
@@ -1256,8 +1256,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