Skip to content

gh-156765: Fix inaccuracies in the ElementTree documentation - #156766

Merged
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:doc-etree-inaccuracies
Sep 2, 2026
Merged

gh-156765: Fix inaccuracies in the ElementTree documentation#156766
serhiy-storchaka merged 4 commits into
python:mainfrom
serhiy-storchaka:doc-etree-inaccuracies

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Sep 1, 2026

Copy link
Copy Markdown
Member

Several statements in the documentation of xml.etree.ElementTree do not match the behaviour:

  • the parser argument of iterparse() is an instance of XMLParser or its subclass, not a subclass;
  • XMLParser.feed() and XMLPullParser.feed() accept a string as well as encoded data;
  • the element tag, the attribute names and values, the text of a comment and the data of 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 like Comment, and an attribute value can be a QName or, for the HTML method, None.

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.
@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes skip news labels Sep 1, 2026
@read-the-docs-community

read-the-docs-community Bot commented Sep 1, 2026

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34336324 | 📁 Comparing d502d73 against main (faf4e52)

  🔍 Preview build  

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.
@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) September 2, 2026 16:46
@serhiy-storchaka
serhiy-storchaka merged commit 09ff4d4 into python:main Sep 2, 2026
53 of 54 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.14 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 09ff4d443f0dc748bfa4d73c9bb6a22ae8a97993 3.14

@bedevere-app

bedevere-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

GH-156848 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Sep 2, 2026
@miss-islington-app

Copy link
Copy Markdown

Sorry, @serhiy-storchaka, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 09ff4d443f0dc748bfa4d73c9bb6a22ae8a97993 3.13

@bedevere-app

bedevere-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

GH-156849 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Sep 2, 2026
@bedevere-app

bedevere-app Bot commented Sep 2, 2026

Copy link
Copy Markdown

GH-156850 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Sep 2, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant