Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect return types for xml.dom.minidom.Node.{toxml,toprettyxml} #10060

Closed
wesleywright opened this issue Apr 18, 2023 · 0 comments · Fixed by #10061
Closed

Incorrect return types for xml.dom.minidom.Node.{toxml,toprettyxml} #10060

wesleywright opened this issue Apr 18, 2023 · 0 comments · Fixed by #10061
Labels
stubs: false positive Type checkers report false errors

Comments

@wesleywright
Copy link
Contributor

It looks like #9917 added the -> str return type to these functions, but the documentation indicates that may return bytes:

Return a string or byte string containing the XML represented by the DOM node.

With an explicit encoding 1 argument, the result is a byte string in the specified encoding. With no encoding argument, the result is a Unicode string, and the XML declaration in the resulting string does not specify an encoding. Encoding this string in an encoding other than UTF-8 is likely incorrect, since UTF-8 is the default encoding of XML.

This small example seems to confirm that it can return bytes:

from xml.dom.minidom import Document

doc = Document()
doc.appendChild(doc.createElement("foo"))
print(doc.toprettyxml(indent="\t", encoding="UTF-8"))
# output: b'<?xml version="1.0" encoding="UTF-8"?>\n<foo/>\n'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stubs: false positive Type checkers report false errors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants