Add IO protocols to _typeshed (#4230)

This commit is contained in:
Sebastian Rittau
2020-06-14 20:44:48 +02:00
committed by GitHub
parent ef74bee249
commit 51cf2f51b8
21 changed files with 80 additions and 131 deletions

View File

@@ -11,7 +11,6 @@ from typing import (
List,
MutableSequence,
Optional,
Protocol,
Sequence,
Text,
Tuple,
@@ -19,7 +18,7 @@ from typing import (
Union,
overload,
)
from _typeshed import AnyPath, FileDescriptor
from _typeshed import AnyPath, FileDescriptor, SupportsWrite
import sys
from typing_extensions import Literal
@@ -60,9 +59,6 @@ else:
_file_or_filename = Union[AnyPath, FileDescriptor, IO[Any]]
if sys.version_info >= (3, 8):
class _Writeable(Protocol):
def write(self, __s: str) -> Any: ...
@overload
def canonicalize(
xml_data: Optional[_parser_input_type] = ...,
@@ -81,7 +77,7 @@ if sys.version_info >= (3, 8):
def canonicalize(
xml_data: Optional[_parser_input_type] = ...,
*,
out: _Writeable,
out: SupportsWrite[str],
from_file: Optional[_file_or_filename] = ...,
with_comments: bool = ...,
strip_text: bool = ...,

View File

@@ -1,23 +1,21 @@
import sys
from typing import Mapping, Text, Optional, Protocol, Union, TextIO
from typing import Mapping, Text, Optional, Union, TextIO
from io import TextIOBase, RawIOBase
from codecs import StreamWriter, StreamReaderWriter
from _typeshed import SupportsWrite
from xml.sax import handler
from xml.sax import xmlreader
class _Writable(Protocol):
def write(self, data: str) -> None: ...
def escape(data: Text, entities: Mapping[Text, Text] = ...) -> Text: ...
def unescape(data: Text, entities: Mapping[Text, Text] = ...) -> Text: ...
def quoteattr(data: Text, entities: Mapping[Text, Text] = ...) -> Text: ...
class XMLGenerator(handler.ContentHandler):
if sys.version_info >= (3, 0):
def __init__(self, out: Optional[Union[TextIOBase, RawIOBase, StreamWriter, StreamReaderWriter, _Writable]] = ..., encoding: str = ..., short_empty_elements: bool = ...) -> None: ...
def __init__(self, out: Optional[Union[TextIOBase, RawIOBase, StreamWriter, StreamReaderWriter, SupportsWrite[str]]] = ..., encoding: str = ..., short_empty_elements: bool = ...) -> None: ...
else:
def __init__(self, out: Optional[Union[TextIOBase, RawIOBase, StreamWriter, StreamReaderWriter, _Writable]] = ..., encoding: Text = ...) -> None: ...
def __init__(self, out: Optional[Union[TextIOBase, RawIOBase, StreamWriter, StreamReaderWriter, SupportsWrite[str]]] = ..., encoding: Text = ...) -> None: ...
def startDocument(self): ...
def endDocument(self): ...
def startPrefixMapping(self, prefix, uri): ...