Skip to content

Remove leftover bytes support from _elementtree #157366

Description

@serhiy-storchaka

Bug report

Modules/_elementtree.c still has four places which accept bytes. They are the result of improper translation of the PyString C API used in Python 2 to PyBytes (72b710a). The Python implementation of xml.etree.ElementTree accepts only str there, and gh-72424 declared bytes unsupported.

  1. checkpath() checks a bytes path for XPath characters, so find(), findall() and findtext() with a bytes path return None/[]/'' instead of raising TypeError like iterfind() and the Python implementation.
  2. Element.iter() treats b'*' as a wildcard.
  3. XMLParser._setevents() accepts bytes event names, like b'start'. The Python implementation raises ValueError; the events were documented as strings in cElementTree iterparse requires events as bytes; ElementTree uses strings #53503.
  4. treebuilder_handle_data() concatenates a one-byte bytes to a bytes. It is dead code: the parser always passes str.

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions