diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-01-31 12:03:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 12:03:08 (GMT) |
commit | 3982049a3054b0503b09d9b9d2a1735a3195048c (patch) | |
tree | dd7a2091b3411943516ebbeed7b65757d8722704 | |
parent | ad6233396a323c0a6e90edd3c9b2b832928acb92 (diff) | |
download | cpython-3982049a3054b0503b09d9b9d2a1735a3195048c.zip cpython-3982049a3054b0503b09d9b9d2a1735a3195048c.tar.gz cpython-3982049a3054b0503b09d9b9d2a1735a3195048c.tar.bz2 |
[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 <colesbury@gmail.com>
-rw-r--r-- | Lib/test/test_xml_etree.py | 2 | ||||
-rw-r--r-- | Lib/xml/etree/ElementTree.py | 2 |
2 files changed, 3 insertions, 1 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 57f5de3..267982a 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 d4b259e..fce0c29 100644 --- a/Lib/xml/etree/ElementTree.py +++ b/Lib/xml/etree/ElementTree.py @@ -1271,8 +1271,8 @@ def iterparse(source, events=None, parser=None): source.close() it = IterParseIterator() + it.root = None wr = weakref.ref(it) - del IterParseIterator return it |