mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
Remove compatibility aliases (#5464)
* Remove compatibility aliases Remove a few instances of Text Use aliases from _typeshed * Remove unused imports
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import sys
|
||||
import xml.dom
|
||||
from typing import IO, Any, Optional, Text as _Text, TypeVar, Union
|
||||
from typing import IO, Any, Optional, TypeVar, Union
|
||||
from xml.dom.xmlbuilder import DocumentLS, DOMImplementationLS
|
||||
from xml.sax.xmlreader import XMLReader
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
def parse(file: Union[str, IO[Any]], parser: Optional[XMLReader] = ..., bufsize: Optional[int] = ...): ...
|
||||
def parseString(string: Union[bytes, _Text], parser: Optional[XMLReader] = ...): ...
|
||||
def parseString(string: Union[str, bytes], parser: Optional[XMLReader] = ...): ...
|
||||
def getDOMImplementation(features=...): ...
|
||||
|
||||
class Node(xml.dom.Node):
|
||||
|
||||
@@ -14,7 +14,6 @@ from typing import (
|
||||
MutableSequence,
|
||||
Optional,
|
||||
Sequence,
|
||||
Text,
|
||||
Tuple,
|
||||
TypeVar,
|
||||
Union,
|
||||
@@ -22,6 +21,9 @@ from typing import (
|
||||
)
|
||||
from typing_extensions import Literal
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_File = Union[AnyPath, FileDescriptor, IO[Any]]
|
||||
|
||||
VERSION: str
|
||||
|
||||
class ParseError(SyntaxError):
|
||||
@@ -30,34 +32,13 @@ class ParseError(SyntaxError):
|
||||
|
||||
def iselement(element: object) -> bool: ...
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
# Type for parser inputs. Parser will accept any unicode/str/bytes and coerce,
|
||||
# and this is true in py2 and py3 (even fromstringlist() in python3 can be
|
||||
# called with a heterogeneous list)
|
||||
_parser_input_type = Union[bytes, Text]
|
||||
|
||||
# Type for individual tag/attr/ns/text values in args to most functions.
|
||||
# In py2, the library accepts str or unicode everywhere and coerces
|
||||
# aggressively.
|
||||
# In py3, bytes is not coerced to str and so use of bytes is probably an error,
|
||||
# so we exclude it. (why? the parser never produces bytes when it parses XML,
|
||||
# so e.g., element.get(b'name') will always return None for parsed XML, even if
|
||||
# there is a 'name' attribute.)
|
||||
_str_argument_type = Union[str, Text]
|
||||
|
||||
# Type for return values from individual tag/attr/text values
|
||||
_str_result_type = str
|
||||
|
||||
_file_or_filename = Union[AnyPath, FileDescriptor, IO[Any]]
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
def canonicalize(
|
||||
xml_data: Optional[_parser_input_type] = ...,
|
||||
xml_data: Optional[Union[str, bytes]] = ...,
|
||||
*,
|
||||
out: None = ...,
|
||||
from_file: Optional[_file_or_filename] = ...,
|
||||
from_file: Optional[_File] = ...,
|
||||
with_comments: bool = ...,
|
||||
strip_text: bool = ...,
|
||||
rewrite_prefixes: bool = ...,
|
||||
@@ -68,10 +49,10 @@ if sys.version_info >= (3, 8):
|
||||
) -> str: ...
|
||||
@overload
|
||||
def canonicalize(
|
||||
xml_data: Optional[_parser_input_type] = ...,
|
||||
xml_data: Optional[Union[str, bytes]] = ...,
|
||||
*,
|
||||
out: SupportsWrite[str],
|
||||
from_file: Optional[_file_or_filename] = ...,
|
||||
from_file: Optional[_File] = ...,
|
||||
with_comments: bool = ...,
|
||||
strip_text: bool = ...,
|
||||
rewrite_prefixes: bool = ...,
|
||||
@@ -82,51 +63,33 @@ if sys.version_info >= (3, 8):
|
||||
) -> None: ...
|
||||
|
||||
class Element(MutableSequence[Element]):
|
||||
tag: _str_result_type
|
||||
attrib: Dict[_str_result_type, _str_result_type]
|
||||
text: Optional[_str_result_type]
|
||||
tail: Optional[_str_result_type]
|
||||
def __init__(
|
||||
self,
|
||||
tag: Union[_str_argument_type, Callable[..., Element]],
|
||||
attrib: Dict[_str_argument_type, _str_argument_type] = ...,
|
||||
**extra: _str_argument_type,
|
||||
) -> None: ...
|
||||
tag: str
|
||||
attrib: Dict[str, str]
|
||||
text: Optional[str]
|
||||
tail: Optional[str]
|
||||
def __init__(self, tag: Union[str, Callable[..., Element]], attrib: Dict[str, str] = ..., **extra: str) -> None: ...
|
||||
def append(self, __subelement: Element) -> None: ...
|
||||
def clear(self) -> None: ...
|
||||
def extend(self, __elements: Iterable[Element]) -> None: ...
|
||||
def find(
|
||||
self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> Optional[Element]: ...
|
||||
def findall(
|
||||
self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> List[Element]: ...
|
||||
def find(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Optional[Element]: ...
|
||||
def findall(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> List[Element]: ...
|
||||
@overload
|
||||
def findtext(
|
||||
self,
|
||||
path: _str_argument_type,
|
||||
default: None = ...,
|
||||
namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...,
|
||||
) -> Optional[_str_result_type]: ...
|
||||
def findtext(self, path: str, default: None = ..., namespaces: Optional[Dict[str, str]] = ...) -> Optional[str]: ...
|
||||
@overload
|
||||
def findtext(
|
||||
self, path: _str_argument_type, default: _T, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> Union[_T, _str_result_type]: ...
|
||||
def findtext(self, path: str, default: _T, namespaces: Optional[Dict[str, str]] = ...) -> Union[_T, str]: ...
|
||||
@overload
|
||||
def get(self, key: _str_argument_type, default: None = ...) -> Optional[_str_result_type]: ...
|
||||
def get(self, key: str, default: None = ...) -> Optional[str]: ...
|
||||
@overload
|
||||
def get(self, key: _str_argument_type, default: _T) -> Union[_str_result_type, _T]: ...
|
||||
def get(self, key: str, default: _T) -> Union[str, _T]: ...
|
||||
def insert(self, __index: int, __subelement: Element) -> None: ...
|
||||
def items(self) -> ItemsView[_str_result_type, _str_result_type]: ...
|
||||
def iter(self, tag: Optional[_str_argument_type] = ...) -> Generator[Element, None, None]: ...
|
||||
def iterfind(
|
||||
self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> Generator[Element, None, None]: ...
|
||||
def itertext(self) -> Generator[_str_result_type, None, None]: ...
|
||||
def keys(self) -> KeysView[_str_result_type]: ...
|
||||
def makeelement(self, __tag: _str_argument_type, __attrib: Dict[_str_argument_type, _str_argument_type]) -> Element: ...
|
||||
def items(self) -> ItemsView[str, str]: ...
|
||||
def iter(self, tag: Optional[str] = ...) -> Generator[Element, None, None]: ...
|
||||
def iterfind(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Generator[Element, None, None]: ...
|
||||
def itertext(self) -> Generator[str, None, None]: ...
|
||||
def keys(self) -> KeysView[str]: ...
|
||||
def makeelement(self, __tag: str, __attrib: Dict[str, str]) -> Element: ...
|
||||
def remove(self, __subelement: Element) -> None: ...
|
||||
def set(self, __key: _str_argument_type, __value: _str_argument_type) -> None: ...
|
||||
def set(self, __key: str, __value: str) -> None: ...
|
||||
def __delitem__(self, i: Union[int, slice]) -> None: ...
|
||||
@overload
|
||||
def __getitem__(self, i: int) -> Element: ...
|
||||
@@ -139,63 +102,45 @@ class Element(MutableSequence[Element]):
|
||||
def __setitem__(self, s: slice, o: Iterable[Element]) -> None: ...
|
||||
if sys.version_info < (3, 9):
|
||||
def getchildren(self) -> List[Element]: ...
|
||||
def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ...
|
||||
def getiterator(self, tag: Optional[str] = ...) -> List[Element]: ...
|
||||
|
||||
def SubElement(
|
||||
parent: Element,
|
||||
tag: _str_argument_type,
|
||||
attrib: Dict[_str_argument_type, _str_argument_type] = ...,
|
||||
**extra: _str_argument_type,
|
||||
) -> Element: ...
|
||||
def Comment(text: Optional[_str_argument_type] = ...) -> Element: ...
|
||||
def ProcessingInstruction(target: _str_argument_type, text: Optional[_str_argument_type] = ...) -> Element: ...
|
||||
def SubElement(parent: Element, tag: str, attrib: Dict[str, str] = ..., **extra: str) -> Element: ...
|
||||
def Comment(text: Optional[str] = ...) -> Element: ...
|
||||
def ProcessingInstruction(target: str, text: Optional[str] = ...) -> Element: ...
|
||||
|
||||
PI: Callable[..., Element]
|
||||
|
||||
class QName:
|
||||
text: str
|
||||
def __init__(self, text_or_uri: _str_argument_type, tag: Optional[_str_argument_type] = ...) -> None: ...
|
||||
def __init__(self, text_or_uri: str, tag: Optional[str] = ...) -> None: ...
|
||||
|
||||
class ElementTree:
|
||||
def __init__(self, element: Optional[Element] = ..., file: Optional[_file_or_filename] = ...) -> None: ...
|
||||
def __init__(self, element: Optional[Element] = ..., file: Optional[_File] = ...) -> None: ...
|
||||
def getroot(self) -> Element: ...
|
||||
def parse(self, source: _file_or_filename, parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
def iter(self, tag: Optional[_str_argument_type] = ...) -> Generator[Element, None, None]: ...
|
||||
def parse(self, source: _File, parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
def iter(self, tag: Optional[str] = ...) -> Generator[Element, None, None]: ...
|
||||
if sys.version_info < (3, 9):
|
||||
def getiterator(self, tag: Optional[_str_argument_type] = ...) -> List[Element]: ...
|
||||
def find(
|
||||
self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> Optional[Element]: ...
|
||||
def getiterator(self, tag: Optional[str] = ...) -> List[Element]: ...
|
||||
def find(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Optional[Element]: ...
|
||||
@overload
|
||||
def findtext(
|
||||
self,
|
||||
path: _str_argument_type,
|
||||
default: None = ...,
|
||||
namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...,
|
||||
) -> Optional[_str_result_type]: ...
|
||||
def findtext(self, path: str, default: None = ..., namespaces: Optional[Dict[str, str]] = ...) -> Optional[str]: ...
|
||||
@overload
|
||||
def findtext(
|
||||
self, path: _str_argument_type, default: _T, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> Union[_T, _str_result_type]: ...
|
||||
def findall(
|
||||
self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> List[Element]: ...
|
||||
def iterfind(
|
||||
self, path: _str_argument_type, namespaces: Optional[Dict[_str_argument_type, _str_argument_type]] = ...
|
||||
) -> Generator[Element, None, None]: ...
|
||||
def findtext(self, path: str, default: _T, namespaces: Optional[Dict[str, str]] = ...) -> Union[_T, str]: ...
|
||||
def findall(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> List[Element]: ...
|
||||
def iterfind(self, path: str, namespaces: Optional[Dict[str, str]] = ...) -> Generator[Element, None, None]: ...
|
||||
def write(
|
||||
self,
|
||||
file_or_filename: _file_or_filename,
|
||||
file_or_filename: _File,
|
||||
encoding: Optional[str] = ...,
|
||||
xml_declaration: Optional[bool] = ...,
|
||||
default_namespace: Optional[_str_argument_type] = ...,
|
||||
default_namespace: Optional[str] = ...,
|
||||
method: Optional[str] = ...,
|
||||
*,
|
||||
short_empty_elements: bool = ...,
|
||||
) -> None: ...
|
||||
def write_c14n(self, file: _file_or_filename) -> None: ...
|
||||
def write_c14n(self, file: _File) -> None: ...
|
||||
|
||||
def register_namespace(prefix: _str_argument_type, uri: _str_argument_type) -> None: ...
|
||||
def register_namespace(prefix: str, uri: str) -> None: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
@@ -205,7 +150,7 @@ if sys.version_info >= (3, 8):
|
||||
method: Optional[str] = ...,
|
||||
*,
|
||||
xml_declaration: Optional[bool] = ...,
|
||||
default_namespace: Optional[_str_argument_type] = ...,
|
||||
default_namespace: Optional[str] = ...,
|
||||
short_empty_elements: bool = ...,
|
||||
) -> bytes: ...
|
||||
@overload
|
||||
@@ -215,7 +160,7 @@ if sys.version_info >= (3, 8):
|
||||
method: Optional[str] = ...,
|
||||
*,
|
||||
xml_declaration: Optional[bool] = ...,
|
||||
default_namespace: Optional[_str_argument_type] = ...,
|
||||
default_namespace: Optional[str] = ...,
|
||||
short_empty_elements: bool = ...,
|
||||
) -> str: ...
|
||||
@overload
|
||||
@@ -225,7 +170,7 @@ if sys.version_info >= (3, 8):
|
||||
method: Optional[str] = ...,
|
||||
*,
|
||||
xml_declaration: Optional[bool] = ...,
|
||||
default_namespace: Optional[_str_argument_type] = ...,
|
||||
default_namespace: Optional[str] = ...,
|
||||
short_empty_elements: bool = ...,
|
||||
) -> Any: ...
|
||||
@overload
|
||||
@@ -235,7 +180,7 @@ if sys.version_info >= (3, 8):
|
||||
method: Optional[str] = ...,
|
||||
*,
|
||||
xml_declaration: Optional[bool] = ...,
|
||||
default_namespace: Optional[_str_argument_type] = ...,
|
||||
default_namespace: Optional[str] = ...,
|
||||
short_empty_elements: bool = ...,
|
||||
) -> List[bytes]: ...
|
||||
@overload
|
||||
@@ -245,7 +190,7 @@ if sys.version_info >= (3, 8):
|
||||
method: Optional[str] = ...,
|
||||
*,
|
||||
xml_declaration: Optional[bool] = ...,
|
||||
default_namespace: Optional[_str_argument_type] = ...,
|
||||
default_namespace: Optional[str] = ...,
|
||||
short_empty_elements: bool = ...,
|
||||
) -> List[str]: ...
|
||||
@overload
|
||||
@@ -255,7 +200,7 @@ if sys.version_info >= (3, 8):
|
||||
method: Optional[str] = ...,
|
||||
*,
|
||||
xml_declaration: Optional[bool] = ...,
|
||||
default_namespace: Optional[_str_argument_type] = ...,
|
||||
default_namespace: Optional[str] = ...,
|
||||
short_empty_elements: bool = ...,
|
||||
) -> List[Any]: ...
|
||||
|
||||
@@ -288,9 +233,9 @@ def dump(elem: Element) -> None: ...
|
||||
if sys.version_info >= (3, 9):
|
||||
def indent(tree: Union[Element, ElementTree], space: str = ..., level: int = ...) -> None: ...
|
||||
|
||||
def parse(source: _file_or_filename, parser: Optional[XMLParser] = ...) -> ElementTree: ...
|
||||
def parse(source: _File, parser: Optional[XMLParser] = ...) -> ElementTree: ...
|
||||
def iterparse(
|
||||
source: _file_or_filename, events: Optional[Sequence[str]] = ..., parser: Optional[XMLParser] = ...
|
||||
source: _File, events: Optional[Sequence[str]] = ..., parser: Optional[XMLParser] = ...
|
||||
) -> Iterator[Tuple[str, Any]]: ...
|
||||
|
||||
class XMLPullParser:
|
||||
@@ -299,13 +244,13 @@ class XMLPullParser:
|
||||
def close(self) -> None: ...
|
||||
def read_events(self) -> Iterator[Tuple[str, Element]]: ...
|
||||
|
||||
def XML(text: _parser_input_type, parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
def XMLID(text: _parser_input_type, parser: Optional[XMLParser] = ...) -> Tuple[Element, Dict[_str_result_type, Element]]: ...
|
||||
def XML(text: Union[str, bytes], parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
def XMLID(text: Union[str, bytes], parser: Optional[XMLParser] = ...) -> Tuple[Element, Dict[str, Element]]: ...
|
||||
|
||||
# This is aliased to XML in the source.
|
||||
fromstring = XML
|
||||
|
||||
def fromstringlist(sequence: Sequence[_parser_input_type], parser: Optional[XMLParser] = ...) -> Element: ...
|
||||
def fromstringlist(sequence: Sequence[Union[str, bytes]], parser: Optional[XMLParser] = ...) -> 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
|
||||
@@ -321,9 +266,9 @@ _ElementFactory = Callable[[Any, Dict[Any, Any]], Element]
|
||||
class TreeBuilder:
|
||||
def __init__(self, element_factory: Optional[_ElementFactory] = ...) -> None: ...
|
||||
def close(self) -> Element: ...
|
||||
def data(self, __data: _parser_input_type) -> None: ...
|
||||
def start(self, __tag: _parser_input_type, __attrs: Dict[_parser_input_type, _parser_input_type]) -> Element: ...
|
||||
def end(self, __tag: _parser_input_type) -> Element: ...
|
||||
def data(self, __data: Union[str, bytes]) -> None: ...
|
||||
def start(self, __tag: Union[str, bytes], __attrs: Dict[Union[str, bytes], Union[str, bytes]]) -> Element: ...
|
||||
def end(self, __tag: Union[str, bytes]) -> Element: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
class C14NWriterTarget:
|
||||
@@ -352,4 +297,4 @@ class XMLParser:
|
||||
def __init__(self, html: int = ..., target: Any = ..., encoding: Optional[str] = ...) -> None: ...
|
||||
def doctype(self, __name: str, __pubid: str, __system: str) -> None: ...
|
||||
def close(self) -> Any: ...
|
||||
def feed(self, __data: _parser_input_type) -> None: ...
|
||||
def feed(self, __data: Union[str, bytes]) -> None: ...
|
||||
|
||||
Reference in New Issue
Block a user