gh-156765: Fix inaccuracies in the ElementTree documentation - #156766
Merged
serhiy-storchaka merged 4 commits intoSep 2, 2026
Conversation
The parser argument of iterparse() is an instance of XMLParser or its subclass, not a subclass. feed() accepts a string as well as encoded data. Bytes are no longer said to be supported for the element tag, the attribute names and values and the text of a comment: they are either rejected by the serializer or written as a repr.
Documentation build overview
4 files changed± library/functions.html± library/xml.etree.elementtree.html± whatsnew/3.16.html± whatsnew/changelog.html |
They do not return a list in the Python implementation, which returns dict views. And the attributes are no longer returned in an arbitrary order: the attrib dict preserves the insertion order.
They are strings or QName instances, and the text and the tail can also be None. The element name can also be Comment, ProcessingInstruction or None, and the attribute value can be None for the HTML method.
|
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
|
GH-156848 is a backport of this pull request to the 3.15 branch. |
|
Sorry, @serhiy-storchaka, I could not cleanly backport this to |
This was referenced Sep 2, 2026
|
GH-156849 is a backport of this pull request to the 3.14 branch. |
|
GH-156850 is a backport of this pull request to the 3.13 branch. |
serhiy-storchaka
added a commit
that referenced
this pull request
Sep 2, 2026
…H-156766) (GH-156850) Corrected: * the parser argument of iterparse() is an instance of XMLParser or its subclass, not a subclass; * feed() accepts a string as well as encoded data; * keys() and items() do not return a list in the Python implementation, and the attributes are no longer returned in an arbitrary order. Removed the claims that the element tag, the attribute names and values, the text of a comment and the data of TreeBuilder.data() can be bytes. It is a Python 2 leftover. Documented instead what they can be. (cherry picked from commit 09ff4d4)
serhiy-storchaka
added a commit
that referenced
this pull request
Sep 2, 2026
…H-156766) (GH-156849) Corrected: * the parser argument of iterparse() is an instance of XMLParser or its subclass, not a subclass; * feed() accepts a string as well as encoded data; * keys() and items() do not return a list in the Python implementation, and the attributes are no longer returned in an arbitrary order. Removed the claims that the element tag, the attribute names and values, the text of a comment and the data of TreeBuilder.data() can be bytes. It is a Python 2 leftover. Documented instead what they can be. (cherry picked from commit 09ff4d4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Several statements in the documentation of
xml.etree.ElementTreedo not match the behaviour:iterparse()is an instance ofXMLParseror its subclass, not a subclass;XMLParser.feed()andXMLPullParser.feed()accept a string as well as encoded data;TreeBuilder.data()were said to be either bytestrings or Unicode strings, which is a Python 2 leftover: bytes are either rejected by the serializer or written as a repr.The claims about bytes are removed rather than corrected, because the accurate description is more complicated: a tag can also be
None(a fragment) or a factory likeComment, and an attribute value can be aQNameor, for the HTML method,None.