Skip to content

Incorrect statements in the xml.etree.ElementTree documentation #156765

Description

@serhiy-storchaka

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

  • The parser argument of iterparse() is described as "a subclass of XMLParser", but it is an instance of it.

  • XMLParser.feed() is described as accepting encoded data and XMLPullParser.feed() as accepting bytes, but both accept a string as well, and any bytes-like object.

  • The element tag, the attribute names and values, the text of a comment and the data of TreeBuilder.data() are described as being "either bytestrings or Unicode strings". This is a Python 2 leftover. In Python 3 bytes are either rejected by the serializer or written as a repr:

>>> ET.tostring(ET.Comment(b'spam'))
b"<!--b'spam'-->"
>>> ET.tostring(ET.Element('t', {b'a': 'v'}))
b'<t b\'a\'="v" />'
>>> ET.tostring(ET.Element(b'tag'))
TypeError: cannot serialize b'tag' (type bytes)

The claims about bytes are better removed than corrected: the accurate description is more complicated than it seems, because 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.

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

    docsDocumentation in the Doc dirtopic-XML

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions