-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Typeshed cherry-pick: stdlib/xml: fix return types for toxml/topretty…
…xml methods (#10061)
- Loading branch information
1 parent
6a68049
commit 320b883
Showing
2 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
import sys | ||
from typing_extensions import assert_type | ||
from xml.dom.minidom import Document | ||
|
||
document = Document() | ||
|
||
assert_type(document.toxml(), str) | ||
assert_type(document.toxml(encoding=None), str) | ||
assert_type(document.toxml(encoding="UTF8"), bytes) | ||
assert_type(document.toxml("UTF8"), bytes) | ||
if sys.version_info >= (3, 9): | ||
assert_type(document.toxml(standalone=True), str) | ||
assert_type(document.toxml("UTF8", True), bytes) | ||
assert_type(document.toxml(encoding="UTF8", standalone=True), bytes) | ||
|
||
|
||
# Because toprettyxml can mix positional and keyword variants of the "encoding" argument, which | ||
# determines the return type, the proper stub typing isn't immediately obvious. This is a basic | ||
# brute-force sanity check. | ||
# Test cases like toxml | ||
assert_type(document.toprettyxml(), str) | ||
assert_type(document.toprettyxml(encoding=None), str) | ||
assert_type(document.toprettyxml(encoding="UTF8"), bytes) | ||
if sys.version_info >= (3, 9): | ||
assert_type(document.toprettyxml(standalone=True), str) | ||
assert_type(document.toprettyxml(encoding="UTF8", standalone=True), bytes) | ||
# Test cases unique to toprettyxml | ||
assert_type(document.toprettyxml(" "), str) | ||
assert_type(document.toprettyxml(" ", "\r\n"), str) | ||
assert_type(document.toprettyxml(" ", "\r\n", "UTF8"), bytes) | ||
if sys.version_info >= (3, 9): | ||
assert_type(document.toprettyxml(" ", "\r\n", "UTF8", True), bytes) | ||
assert_type(document.toprettyxml(" ", "\r\n", standalone=True), str) |