Skip to content

gh-157366: Remove leftover bytes support from _elementtree - #157367

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-157366-etree-no-bytes
Sep 12, 2026
Merged

gh-157366: Remove leftover bytes support from _elementtree#157367
serhiy-storchaka merged 2 commits into
python:mainfrom
serhiy-storchaka:gh-157366-etree-no-bytes

Conversation

@serhiy-storchaka

Copy link
Copy Markdown
Member

It was the result of improper translation of the PyString C API used in Python 2 to PyBytes. The Python implementation accepts only str there.

  • checkpath() no longer checks a bytes path for XPath characters, so find(), findall() and findtext() with a bytes path now raise TypeError, like iterfind() and the Python implementation.
  • Element.iter() no longer treats b'*' as a wildcard.
  • XMLParser no longer accepts bytes event names. Non-str event names are now reported as "unknown event", like in the Python implementation.
  • Remove the dead code for concatenating one-byte bytes in TreeBuilder.

It was the result of improper translation of the PyString C API used in
Python 2 to PyBytes.  The Python implementation accepts only str there.

* checkpath() no longer checks a bytes path for XPath characters, so
  find(), findall() and findtext() with a bytes path now raise TypeError,
  like iterfind() and the Python implementation.
* Element.iter() no longer treats b'*' as a wildcard.
* XMLParser no longer accepts bytes event names.  Non-str event names are
  now reported as "unknown event", like in the Python implementation.
* Remove the dead code for concatenating one-byte bytes in TreeBuilder.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Your PR is more complete than mine :-) I closed my PR gh-157342.

@vstinner

vstinner commented Sep 12, 2026

Copy link
Copy Markdown
Member

The change is correct because when bytes support is removed, there is still a similar code for str support. data() only had bytes and list support, but the bytes support is a mistake and it should be removed. In Python 3, data must be str, not bytes.

@serhiy-storchaka
serhiy-storchaka enabled auto-merge (squash) September 12, 2026 18:20
@serhiy-storchaka
serhiy-storchaka merged commit b1e7554 into python:main Sep 12, 2026
98 of 100 checks passed
@serhiy-storchaka
serhiy-storchaka deleted the gh-157366-etree-no-bytes branch September 12, 2026 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants