-
-
Notifications
You must be signed in to change notification settings - Fork 2k
xml: improve bytes types #9110
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
xml: improve bytes types #9110
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import sys | ||
| from _collections_abc import dict_keys | ||
| from _typeshed import FileDescriptor, StrOrBytesPath, SupportsRead, SupportsWrite | ||
| from _typeshed import FileDescriptor, ReadableBuffer, StrOrBytesPath, SupportsRead, SupportsWrite | ||
| from collections.abc import Callable, Generator, ItemsView, Iterable, Iterator, Mapping, Sequence | ||
| from typing import Any, TypeVar, overload | ||
| from typing_extensions import Literal, SupportsIndex, TypeAlias, TypeGuard | ||
|
|
@@ -54,7 +54,7 @@ def iselement(element: object) -> TypeGuard[Element]: ... | |
| if sys.version_info >= (3, 8): | ||
| @overload | ||
| def canonicalize( | ||
| xml_data: str | bytes | None = ..., | ||
| xml_data: str | ReadableBuffer | None = ..., | ||
| *, | ||
| out: None = ..., | ||
| from_file: _FileRead | None = ..., | ||
|
|
@@ -68,7 +68,7 @@ if sys.version_info >= (3, 8): | |
| ) -> str: ... | ||
| @overload | ||
| def canonicalize( | ||
| xml_data: str | bytes | None = ..., | ||
| xml_data: str | ReadableBuffer | None = ..., | ||
| *, | ||
| out: SupportsWrite[str], | ||
| from_file: _FileRead | None = ..., | ||
|
|
@@ -270,19 +270,19 @@ def iterparse( | |
|
|
||
| class XMLPullParser: | ||
| def __init__(self, events: Sequence[str] | None = ..., *, _parser: XMLParser | None = ...) -> None: ... | ||
| def feed(self, data: str | bytes) -> None: ... | ||
| def feed(self, data: str | ReadableBuffer) -> None: ... | ||
| def close(self) -> None: ... | ||
| # Second element in the tuple could be `Element`, `tuple[str, str]` or `None`. | ||
| # Use `Any` to avoid false-positive errors. | ||
| def read_events(self) -> Iterator[tuple[str, Any]]: ... | ||
|
|
||
| def XML(text: str | bytes, parser: XMLParser | None = ...) -> Element: ... | ||
| def XMLID(text: str | bytes, parser: XMLParser | None = ...) -> tuple[Element, dict[str, Element]]: ... | ||
| def XML(text: str | ReadableBuffer, parser: XMLParser | None = ...) -> Element: ... | ||
| def XMLID(text: str | ReadableBuffer, parser: XMLParser | None = ...) -> tuple[Element, dict[str, Element]]: ... | ||
|
|
||
| # This is aliased to XML in the source. | ||
| fromstring = XML | ||
|
|
||
| def fromstringlist(sequence: Sequence[str | bytes], parser: XMLParser | None = ...) -> Element: ... | ||
| def fromstringlist(sequence: Sequence[str | ReadableBuffer], parser: XMLParser | None = ...) -> Element: ... | ||
|
|
||
| # This type is both not precise enough and too precise. The TreeBuilder | ||
| # requires the elementfactory to accept tag and attrs in its args and produce | ||
|
|
@@ -313,9 +313,11 @@ class TreeBuilder: | |
| def __init__(self, element_factory: _ElementFactory | None = ...) -> None: ... | ||
|
|
||
| def close(self) -> Element: ... | ||
| def data(self, __data: str | bytes) -> None: ... | ||
| def start(self, __tag: str | bytes, __attrs: dict[str | bytes, str | bytes]) -> Element: ... | ||
| def end(self, __tag: str | bytes) -> Element: ... | ||
| def data(self, __data: str) -> None: ... | ||
| # tag and attrs are passed to the element_factory, so they could be anything | ||
| # depending on what the particular factory supports. | ||
| def start(self, __tag: Any, __attrs: dict[Any, Any]) -> Element: ... | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be worth keeping the comment, but only changing the type if someone actually complains?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The existing type is pretty hard to achieve due to invariance, so I'd rather not keep it. |
||
| def end(self, __tag: str) -> Element: ... | ||
| if sys.version_info >= (3, 8): | ||
| # These two methods have pos-only parameters in the C implementation | ||
| def comment(self, __text: str | None) -> Element: ... | ||
|
|
@@ -355,4 +357,4 @@ class XMLParser: | |
| def doctype(self, __name: str, __pubid: str, __system: str) -> None: ... | ||
|
|
||
| def close(self) -> Any: ... | ||
| def feed(self, __data: str | bytes) -> None: ... | ||
| def feed(self, __data: str | ReadableBuffer) -> None: ... | ||
Uh oh!
There was an error while loading. Please reload this page.