mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-09 13:34:58 +08:00
xml: improve bytes types (#9110)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import sys
|
||||
from _typeshed import StrOrBytesPath
|
||||
from collections.abc import Callable
|
||||
from xml.etree.ElementTree import Element
|
||||
|
||||
@@ -11,7 +12,7 @@ if sys.version_info >= (3, 9):
|
||||
|
||||
class FatalIncludeError(SyntaxError): ...
|
||||
|
||||
def default_loader(href: str | bytes | int, parse: str, encoding: str | None = ...) -> str | Element: ...
|
||||
def default_loader(href: StrOrBytesPath | int, parse: str, encoding: str | None = ...) -> str | Element: ...
|
||||
|
||||
# TODO: loader is of type default_loader ie it takes a callable that has the
|
||||
# same signature as default_loader. But default_loader has a keyword argument
|
||||
|
||||
@@ -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: ...
|
||||
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: ...
|
||||
|
||||
Reference in New Issue
Block a user