From 36e2be416cc4809905f1a856d1375aeb9b6b4da5 Mon Sep 17 00:00:00 2001 From: tharvik Date: Tue, 10 May 2016 12:54:09 +0200 Subject: [PATCH 1/5] improve io --- stdlib/3.3/xml/etree/ElementTree.pyi | 3 +- stdlib/3.4/xml/etree/ElementTree.pyi | 3 +- stdlib/3.5/xml/etree/ElementTree.pyi | 3 +- stdlib/3/_io.pyi | 48 ------- stdlib/3/io.pyi | 192 +++++++++++---------------- 5 files changed, 86 insertions(+), 163 deletions(-) delete mode 100644 stdlib/3/_io.pyi diff --git a/stdlib/3.3/xml/etree/ElementTree.pyi b/stdlib/3.3/xml/etree/ElementTree.pyi index 652322f9aadd..157345e0328f 100644 --- a/stdlib/3.3/xml/etree/ElementTree.pyi +++ b/stdlib/3.3/xml/etree/ElementTree.pyi @@ -2,7 +2,7 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator +from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, no_type_check import io VERSION = ... # type: str @@ -80,6 +80,7 @@ class _ListDataStream(io.BufferedIOBase): def __init__(self, lst) -> None: ... def writable(self) -> bool: ... def seekable(self) -> bool: ... + @no_type_check # not same signature as parent def write(self, b: str) -> None: ... def tell(self) -> int: ... diff --git a/stdlib/3.4/xml/etree/ElementTree.pyi b/stdlib/3.4/xml/etree/ElementTree.pyi index 73b49df2aeec..33c7a6be32d8 100644 --- a/stdlib/3.4/xml/etree/ElementTree.pyi +++ b/stdlib/3.4/xml/etree/ElementTree.pyi @@ -2,7 +2,7 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator +from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, no_type_check import io VERSION = ... # type: str @@ -80,6 +80,7 @@ class _ListDataStream(io.BufferedIOBase): def __init__(self, lst) -> None: ... def writable(self) -> bool: ... def seekable(self) -> bool: ... + @no_type_check # not same signature as parent def write(self, b: str) -> None: ... def tell(self) -> int: ... diff --git a/stdlib/3.5/xml/etree/ElementTree.pyi b/stdlib/3.5/xml/etree/ElementTree.pyi index 73b49df2aeec..33c7a6be32d8 100644 --- a/stdlib/3.5/xml/etree/ElementTree.pyi +++ b/stdlib/3.5/xml/etree/ElementTree.pyi @@ -2,7 +2,7 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator +from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, no_type_check import io VERSION = ... # type: str @@ -80,6 +80,7 @@ class _ListDataStream(io.BufferedIOBase): def __init__(self, lst) -> None: ... def writable(self) -> bool: ... def seekable(self) -> bool: ... + @no_type_check # not same signature as parent def write(self, b: str) -> None: ... def tell(self) -> int: ... diff --git a/stdlib/3/_io.pyi b/stdlib/3/_io.pyi deleted file mode 100644 index f67f98925f98..000000000000 --- a/stdlib/3/_io.pyi +++ /dev/null @@ -1,48 +0,0 @@ -# Stubs for _io (Python 3.4) -# -# NOTE: This dynamically typed stub was automatically generated by stubgen. - -from typing import Any - -class _IOBase: - def __init__(self, *args, **kwargs) -> None: ... - @property - def closed(self): ... - def close(self): ... - def fileno(self): ... - def flush(self): ... - def isatty(self): ... - def readable(self): ... - def readline(self, size: int = ...): ... - def readlines(self, hint: int = ...): ... - def seek(self, offset, whence=...): ... - def seekable(self): ... - def tell(self): ... - def truncate(self, size: int = ...) -> int: ... - def writable(self): ... - def writelines(self, lines): ... - def __del__(self): ... - def __enter__(self): ... - def __exit__(self, exc_type, exc_val, exc_tb): ... - def __iter__(self): ... - def __next__(self): ... - -class _BufferedIOBase(_IOBase): - def detach(self): ... - def read(self, size: int = ...): ... - def read1(self, size: int = ...): ... - def readinto(self, b): ... - def write(self, b): ... - -class _RawIOBase(_IOBase): - def read(self, size: int = ...): ... - def readall(self): ... - -class _TextIOBase(_IOBase): - encoding = ... # type: Any - errors = ... # type: Any - newlines = ... # type: Any - def detach(self): ... - def read(self, size: int = ...): ... - def readline(self, size: int = ...): ... - def write(self, b): ... diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 2cc7ee999398..8bff81cdf327 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -1,13 +1,13 @@ # Stubs for io -# Based on http://docs.python.org/3.2/library/io.html - -from typing import List, BinaryIO, TextIO, IO, overload, Iterator, Iterable, Any +from typing import ( + List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, no_type_check +) import builtins import codecs -import _io +from types import TracebackType -DEFAULT_BUFFER_SIZE = 0 # type: int +DEFAULT_BUFFER_SIZE = ... # type: int SEEK_SET = ... # type: int SEEK_CUR = ... # type: int SEEK_END = ... # type: int @@ -17,134 +17,102 @@ open = builtins.open class BlockingIOError(OSError): ... class UnsupportedOperation(ValueError, OSError): ... -class IncrementalNewlineDecoder(codecs.IncrementalDecoder): - newlines = ... # type: Any - def __init__(self, *args, **kwargs) -> None: ... - def decode(self, input, final=...): ... - def getstate(self): ... - def reset(self): ... - def setstate(self, state): ... - -class IOBase(_io._IOBase): ... -class RawIOBase(_io._RawIOBase, IOBase): ... -class BufferedIOBase(_io._BufferedIOBase, IOBase): ... -class TextIOBase(_io._TextIOBase, IOBase): ... - -class FileIO(_io._RawIOBase): - closefd = ... # type: Any - mode = ... # type: Any - def __init__(self, name, mode=..., closefd=..., opener=...) -> None: ... - def readinto(self, b): ... - def write(self, b): ... - -class BufferedReader(_io._BufferedIOBase): - mode = ... # type: Any - name = ... # type: Any - raw = ... # type: Any - def __init__(self, raw, buffer_size=...) -> None: ... - def peek(self, size: int = ...): ... - -class BufferedWriter(_io._BufferedIOBase): - mode = ... # type: Any - name = ... # type: Any - raw = ... # type: Any - def __init__(self, raw, buffer_size=...) -> None: ... - -class BufferedRWPair(_io._BufferedIOBase): - def __init__(self, reader, writer, buffer_size=...) -> None: ... - def peek(self, size: int = ...): ... - -class BufferedRandom(_io._BufferedIOBase): - mode = ... # type: Any - name = ... # type: Any - raw = ... # type: Any - def __init__(self, raw, buffer_size=...) -> None: ... - def peek(self, size: int = ...): ... -class BytesIO(BinaryIO): - def __init__(self, initial_bytes: bytes = ...) -> None: ... - # TODO getbuffer - # TODO see comments in BinaryIO for missing functionality - def close(self) -> None: ... +class IOBase: @property + def close(self) -> None: ... def closed(self) -> bool: ... def fileno(self) -> int: ... def flush(self) -> None: ... def isatty(self) -> bool: ... - def read(self, n: int = ...) -> bytes: ... def readable(self) -> bool: ... - def readline(self, limit: int = ...) -> bytes: ... - def readlines(self, hint: int = ...) -> List[bytes]: ... + def readline(self, size: int = ...) -> bytes: ... + def readlines(self, hint: int = ...) ->List[bytes]: ... def seek(self, offset: int, whence: int = ...) -> int: ... def seekable(self) -> bool: ... def tell(self) -> int: ... def truncate(self, size: int = ...) -> int: ... def writable(self) -> bool: ... - @overload - def write(self, s: bytes) -> int: ... - @overload - def write(self, s: bytearray) -> int: ... - def writelines(self, lines: Iterable[bytes]) -> None: ... - def getvalue(self) -> bytes: ... - def read1(self) -> str: ... + def writelines(self, lines: bytes) -> None: ... + def __del__(self) -> None: ... + def __enter__(self) -> 'IOBase': ... + def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... def __iter__(self) -> Iterator[bytes]: ... - def __enter__(self) -> 'BytesIO': ... - def __exit__(self, t: type = None, value: BaseException = None, traceback: Any = None) -> bool: ... + def __next__(self) -> bytes: ... -class StringIO(TextIO): - def __init__(self, initial_value: str = ..., - newline: str = ...) -> None: ... - # TODO see comments in BinaryIO for missing functionality - def close(self) -> None: ... - @property - def closed(self) -> bool: ... - def fileno(self) -> int: ... +class RawIOBase(IOBase): + def read(self, size: int = ...) -> Optional[bytes]: ... + def readall(self) -> bytes: ... + def readinto(self, b: bytearray) -> Optional[int]: ... + def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... + +class BufferedIOBase(IOBase): + def detach(self) -> 'RawIOBase': ... + def read(self, size: Optional[int] = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + def readinto(self, b: bytearray) -> int: ... + def write(self, b: Union[bytes, bytearray]) -> int: ... + + +class FileIO(RawIOBase): + mode = ... # type: str + name = ... # type: Union[int, str] + def __init__(self, name: Union[int, str], mode: str = ..., + closefd: bool = ..., + opener: Optional[Callable[[Union[int, str], int], Union[TextIO, BytesIO]]] = ...) -> None: ... + + +class BytesIO(BinaryIO): + def __init__(self, initial_bytes: bytes = ...) -> None: ... + def getbuffer(self) -> memoryview: ... + def getvalue(self) -> bytes: ... + def read1(self, size: int = ...) -> Optional[bytes]: ... + def readinto1(self, b: bytearray) -> int: ... + +class BufferedReader(BufferedIOBase): + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... + def peek(self, size: int = ...) -> bytes: ... + def read(self, size: int = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + +class BufferedWriter(BufferedIOBase): + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def flush(self) -> None: ... - def isatty(self) -> bool: ... - def read(self, n: int = ...) -> str: ... - def readable(self) -> bool: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... + def write(self, b: Union[bytes, bytearray]) -> int: ... + +class BufferedRandom(BufferedReader, BufferedWriter): + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def seek(self, offset: int, whence: int = ...) -> int: ... - def seekable(self) -> bool: ... def tell(self) -> int: ... - def truncate(self, size: int = ...) -> int: ... - def writable(self) -> bool: ... - def write(self, s: str) -> int: ... - def writelines(self, lines: Iterable[str]) -> None: ... - def getvalue(self) -> str: ... - def __iter__(self) -> Iterator[str]: ... - def __enter__(self) -> 'StringIO': ... - def __exit__(self, t: type = None, value: BaseException = None, traceback: Any = None) -> bool: ... +class BufferedRWPair(BufferedIOBase): + def __init__(self, reader: RawIOBase, writer: RawIOBase, + buffer_size: int = ...) -> None: ... -class TextIOWrapper(TextIO): - # TODO: This is actually a base class of _io._TextIOBase. - # write_through is undocumented but used by subprocess - def __init__(self, buffer: IO[bytes], encoding: str = ..., - errors: str = ..., newline: str = ..., - line_buffering: bool = ..., - write_through: bool = ...) -> None: ... - # TODO see comments in BinaryIO for missing functionality - def close(self) -> None: ... - @property - def closed(self) -> bool: ... - def fileno(self) -> int: ... - def flush(self) -> None: ... - def isatty(self) -> bool: ... - def read(self, n: int = ...) -> str: ... - def readable(self) -> bool: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... + +class TextIOBase(IOBase): + encoding = ... # type: str + errors = ... # type: Optional[str] + def detach(self) -> IOBase: ... + def read(self, size: Optional[int] = ...) -> str: ... + @no_type_check # not same signature as parent + def readline(self, size: int = ...) -> str: ... def seek(self, offset: int, whence: int = ...) -> int: ... - def seekable(self) -> bool: ... def tell(self) -> int: ... - def truncate(self, size: int = ...) -> int: ... - def writable(self) -> bool: ... def write(self, s: str) -> int: ... - def writelines(self, lines: Iterable[str]) -> None: ... - def __iter__(self) -> Iterator[str]: ... - def __enter__(self) -> StringIO: ... - def __exit__(self, t: type = None, value: BaseException = None, traceback: Any = None) -> bool: ... +class TextIOWrapper(TextIOBase): + line_buffering = ... # type: bool + def __init__(self, buffer: BufferedIOBase, encoding: str = ..., + errors: str = ..., newline: Optional[str] = ..., + line_buffering: bool = ..., + write_through: bool = ...) -> None: ... + +class StringIO(TextIOBase): + def __init__(self, initial_value: str = ..., + newline: Optional[str] = ...) -> None: ... + def getvalue(self) -> str: ... + +class IncrementalNewlineDecoder(codecs.IncrementalDecoder): ... From ad4b15e1b118a7bec249d375b66ca5f6feb9ec7a Mon Sep 17 00:00:00 2001 From: tharvik Date: Wed, 11 May 2016 13:26:49 +0200 Subject: [PATCH 2/5] remove internal, unused xml.etree._ListDataStream --- stdlib/3.3/xml/etree/ElementTree.pyi | 12 +----------- stdlib/3.4/xml/etree/ElementTree.pyi | 12 +----------- stdlib/3.5/xml/etree/ElementTree.pyi | 12 +----------- 3 files changed, 3 insertions(+), 33 deletions(-) diff --git a/stdlib/3.3/xml/etree/ElementTree.pyi b/stdlib/3.3/xml/etree/ElementTree.pyi index 157345e0328f..488d6a5f9e90 100644 --- a/stdlib/3.3/xml/etree/ElementTree.pyi +++ b/stdlib/3.3/xml/etree/ElementTree.pyi @@ -2,7 +2,7 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, no_type_check +from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator import io VERSION = ... # type: str @@ -74,16 +74,6 @@ class ElementTree: def register_namespace(prefix: str, uri: str) -> None: ... def tostring(element: Element, encoding: str=..., method: str=...) -> str: ... - -class _ListDataStream(io.BufferedIOBase): - lst = ... # type: List[str] - def __init__(self, lst) -> None: ... - def writable(self) -> bool: ... - def seekable(self) -> bool: ... - @no_type_check # not same signature as parent - def write(self, b: str) -> None: ... - def tell(self) -> int: ... - def tostringlist(element: Element, encoding: str=..., method: str=...) -> List[str]: ... def dump(elem: Element) -> None: ... def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ... diff --git a/stdlib/3.4/xml/etree/ElementTree.pyi b/stdlib/3.4/xml/etree/ElementTree.pyi index 33c7a6be32d8..8b2eecdd1933 100644 --- a/stdlib/3.4/xml/etree/ElementTree.pyi +++ b/stdlib/3.4/xml/etree/ElementTree.pyi @@ -2,7 +2,7 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, no_type_check +from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator import io VERSION = ... # type: str @@ -74,16 +74,6 @@ class ElementTree: def register_namespace(prefix: str, uri: str) -> None: ... def tostring(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> str: ... - -class _ListDataStream(io.BufferedIOBase): - lst = ... # type: List[str] - def __init__(self, lst) -> None: ... - def writable(self) -> bool: ... - def seekable(self) -> bool: ... - @no_type_check # not same signature as parent - def write(self, b: str) -> None: ... - def tell(self) -> int: ... - def tostringlist(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> List[str]: ... def dump(elem: Element) -> None: ... def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ... diff --git a/stdlib/3.5/xml/etree/ElementTree.pyi b/stdlib/3.5/xml/etree/ElementTree.pyi index 33c7a6be32d8..8b2eecdd1933 100644 --- a/stdlib/3.5/xml/etree/ElementTree.pyi +++ b/stdlib/3.5/xml/etree/ElementTree.pyi @@ -2,7 +2,7 @@ # # NOTE: This dynamically typed stub was automatically generated by stubgen. -from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, no_type_check +from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator import io VERSION = ... # type: str @@ -74,16 +74,6 @@ class ElementTree: def register_namespace(prefix: str, uri: str) -> None: ... def tostring(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> str: ... - -class _ListDataStream(io.BufferedIOBase): - lst = ... # type: List[str] - def __init__(self, lst) -> None: ... - def writable(self) -> bool: ... - def seekable(self) -> bool: ... - @no_type_check # not same signature as parent - def write(self, b: str) -> None: ... - def tell(self) -> int: ... - def tostringlist(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> List[str]: ... def dump(elem: Element) -> None: ... def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ... From a779e0a5eee0af93d040edae0974f58a07584103 Mon Sep 17 00:00:00 2001 From: tharvik Date: Wed, 11 May 2016 09:44:26 +0200 Subject: [PATCH 3/5] add version specific io --- stdlib/3/io.pyi | 209 ++++++++++++++++++++++++++++++++++-------------- 1 file changed, 148 insertions(+), 61 deletions(-) diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 8bff81cdf327..64743b377d6a 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -1,118 +1,205 @@ # Stubs for io from typing import ( - List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, no_type_check + List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, Tuple ) import builtins import codecs +import sys from types import TracebackType DEFAULT_BUFFER_SIZE = ... # type: int -SEEK_SET = ... # type: int -SEEK_CUR = ... # type: int -SEEK_END = ... # type: int -open = builtins.open +if sys.version_info >= (3, 1): + SEEK_SET = ... # type: int + SEEK_CUR = ... # type: int + SEEK_END = ... # type: int -class BlockingIOError(OSError): ... -class UnsupportedOperation(ValueError, OSError): ... +open = builtins.open +if sys.version_info >= (3, 3): + BlockingIOError = BlockingIOError + class UnsupportedOperation(OSError, ValueError): ... +else: + class BlockingIOError(IOError): + characters_written = ... # type: int + class UnsupportedOperation(IOError, ValueError): ... class IOBase: - @property + def __iter__(self) -> Iterator[bytes]: ... + def __next__(self) -> bytes: ... + def __enter__(self) -> 'IOBase': ... + def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], + exc_tb: Optional[TracebackType]) -> bool: ... def close(self) -> None: ... - def closed(self) -> bool: ... def fileno(self) -> int: ... def flush(self) -> None: ... def isatty(self) -> bool: ... def readable(self) -> bool: ... - def readline(self, size: int = ...) -> bytes: ... - def readlines(self, hint: int = ...) ->List[bytes]: ... + def readlines(self, hint: int = ...) -> List[bytes]: ... def seek(self, offset: int, whence: int = ...) -> int: ... def seekable(self) -> bool: ... def tell(self) -> int: ... - def truncate(self, size: int = ...) -> int: ... - def writable(self) -> bool: ... - def writelines(self, lines: bytes) -> None: ... - def __del__(self) -> None: ... - - def __enter__(self) -> 'IOBase': ... - def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], - exc_tb: Optional[TracebackType]) -> bool: ... - def __iter__(self) -> Iterator[bytes]: ... - def __next__(self) -> bytes: ... + if sys.version_info >= (3, 4): + def readline(self, size: int = ...) -> bytes: ... + def __del__(self) -> None: ... + else: + def readline(self, limit: int = ...) -> bytes: ... # type: ignore + if sys.version_info >= (3, 2): + closed = ... # type: bool + else: + def closed(self) -> bool: ... # type: ignore + if sys.version_info >= (3, 1): + def truncate(self, size: Optional[int] = ...) -> int: ... + else: + def truncate(self, size: int = ...) -> int: ... + if sys.version_info >= (3, 1): + def writable(self) -> bool: ... + def writelines(self, lines: bytes) -> None: ... class RawIOBase(IOBase): - def read(self, size: int = ...) -> Optional[bytes]: ... def readall(self) -> bytes: ... - def readinto(self, b: bytearray) -> Optional[int]: ... - def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... + if sys.version_info >= (3, 4): + def read(self, size: int = ...) -> Optional[bytes]: ... + else: + def read(self, n: int = ...) -> Optional[bytes]: ... # type: ignore + if sys.version_info >= (3, 1): + def readinto(self, b: bytearray) -> Optional[int]: ... + def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... + else: + def readinto(self, b: bytearray) -> int: ... + def write(self, b: Union[bytes, bytearray]) -> int: ... class BufferedIOBase(IOBase): - def detach(self) -> 'RawIOBase': ... - def read(self, size: Optional[int] = ...) -> bytes: ... - def read1(self, size: int = ...) -> bytes: ... def readinto(self, b: bytearray) -> int: ... def write(self, b: Union[bytes, bytearray]) -> int: ... + if sys.version_info >= (3, 5): + def readinto1(self, b: bytearray) -> int: ... + if sys.version_info >= (3, 4): + def read(self, size: Optional[int] = ...) -> bytes: ... + def read1(self, size: int = ...) -> bytes: ... + elif sys.version_info >= (3, 1): + def read(self, n: Optional[int] = ...) -> bytes: ... # type: ignore + def read1(self, n: int = ...) -> bytes: ... # type: ignore + if sys.version_info >= (3, 1): + def detach(self) -> 'RawIOBase': ... class FileIO(RawIOBase): mode = ... # type: str name = ... # type: Union[int, str] - def __init__(self, name: Union[int, str], mode: str = ..., - closefd: bool = ..., - opener: Optional[Callable[[Union[int, str], int], Union[TextIO, BytesIO]]] = ...) -> None: ... - - -class BytesIO(BinaryIO): - def __init__(self, initial_bytes: bytes = ...) -> None: ... - def getbuffer(self) -> memoryview: ... + if sys.version_info >= (3, 3): + def __init__(self, name: Union[str, bytes, int], mode: str = ..., + closefd: bool = ..., + opener: Optional[ + Callable[[Union[int, str], str], int]] = ...) \ + -> None: ... + elif sys.version_info >= (3, 1): + def __init__(self, name: Union[str, bytes, int], # type: ignore + mode: str = ..., closefd: bool = ...) -> None: ... + else: + def __init__(self, name: str, # type: ignore + mode: str = ...) -> None: ... + + +class BytesIO(BufferedIOBase): + if sys.version_info >= (3, 1): + def __init__(self, initial_bytes: bytes = ...) -> None: ... + else: + def __init__(self, # type: ignore + initial_bytes: bytearray = ...) -> None: ... def getvalue(self) -> bytes: ... - def read1(self, size: int = ...) -> Optional[bytes]: ... - def readinto1(self, b: bytearray) -> int: ... + if sys.version_info >= (3, 2): + def getbuffer(self) -> memoryview: ... + if sys.version_info < (3, 1): + def read1(self) -> bytes: ... # type: ignore class BufferedReader(BufferedIOBase): def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... - def peek(self, size: int = ...) -> bytes: ... - def read(self, size: int = ...) -> bytes: ... - def read1(self, size: int = ...) -> bytes: ... + if sys.version_info >= (3, 4): + def peek(self, size: int = ...) -> bytes: ... + else: + def peek(self, n: int = ...) -> bytes: ... # type: ignore + if sys.version_info < (3, 1): + def read1(self, n: int = ...) -> bytes: ... class BufferedWriter(BufferedIOBase): - def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... + if sys.version_info >= (3, 1): + def __init__(self, raw: RawIOBase, + buffer_size: int = ...) -> None: ... + else: + def __init__(self, raw: RawIOBase, # type: ignore + buffer_size: int = ..., max_buffer_size: int = ...) \ + -> None: ... def flush(self) -> None: ... def write(self, b: Union[bytes, bytearray]) -> int: ... class BufferedRandom(BufferedReader, BufferedWriter): - def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... - def seek(self, offset: int, whence: int = ...) -> int: ... - def tell(self) -> int: ... + if sys.version_info >= (3, 1): + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + else: + def __init__(self, raw: RawIOBase, # type: ignore + buffer_size: int = ..., max_buffer_size: int = ...) \ + -> None: ... class BufferedRWPair(BufferedIOBase): - def __init__(self, reader: RawIOBase, writer: RawIOBase, - buffer_size: int = ...) -> None: ... + if sys.version_info >= (3, 1): + def __init__(self, reader: RawIOBase, writer: RawIOBase, + buffer_size: int = ...) -> None: ... + else: + def __init__(self, reader: RawIOBase, writer: RawIOBase, # type: ignore + buffer_size: int = ..., max_buffer_size: int = ...) \ + -> None: ... class TextIOBase(IOBase): encoding = ... # type: str - errors = ... # type: Optional[str] - def detach(self) -> IOBase: ... - def read(self, size: Optional[int] = ...) -> str: ... - @no_type_check # not same signature as parent - def readline(self, size: int = ...) -> str: ... - def seek(self, offset: int, whence: int = ...) -> int: ... - def tell(self) -> int: ... + newlines = ... # type: Union[str, Tuple[str, ...], None] + def __iter__(self) -> Iterator[str]: ... # type: ignore + def __next__(self) -> str: ... # type: ignore + def __enter__(self) -> 'TextIOBase': ... def write(self, s: str) -> int: ... + if sys.version_info >= (3, 4): + def readline(self, size: int = ...) -> str: ... # type: ignore + def read(self, size: Optional[int] = ...) -> str: ... + elif sys.version_info >= (3, 2): + def readline(self, limit: int = ...) -> str: ... # type: ignore + else: + def readline(self) -> str: ... # type: ignore + if sys.version_info >= (3, 2): + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... + if sys.version_info >= (3, 1): + errors = ... # type: Optional[str] + def detach(self) -> IOBase: ... + else: + def read(self, n: Optional[int] = ...) -> str: ... # type: ignore class TextIOWrapper(TextIOBase): line_buffering = ... # type: bool - def __init__(self, buffer: BufferedIOBase, encoding: str = ..., - errors: str = ..., newline: Optional[str] = ..., - line_buffering: bool = ..., - write_through: bool = ...) -> None: ... - -class StringIO(TextIOBase): - def __init__(self, initial_value: str = ..., - newline: Optional[str] = ...) -> None: ... + if sys.version_info >= (3, 3): + def __init__(self, buffer: BufferedIOBase, encoding: str = ..., + errors: Optional[str] = ..., newline: Optional[str] = ..., + line_buffering: bool = ..., write_through: bool = ...) \ + -> None: ... + else: + def __init__(self, buffer: BufferedIOBase, # type: ignore + encoding: str = ..., errors: Optional[str] = ..., + newline: Optional[str] = ..., line_buffering: bool = ...) \ + -> None: ... + if sys.version_info < (3, 1): + errors = ... # type: Optional[str] + +class StringIO(TextIOWrapper): + if sys.version_info >= (3, 1): + def __init__(self, initial_value: str = ..., + newline: Optional[str] = ...) -> None: ... + else: + def __init__(self, initial_value: str = ..., # type: ignore + encoding: str = ..., errors: Optional[str] = ..., + newline: Optional[str] = ...) -> None: ... def getvalue(self) -> str: ... class IncrementalNewlineDecoder(codecs.IncrementalDecoder): ... From 0336639eae23f224617e65e1be328d953d00b3a9 Mon Sep 17 00:00:00 2001 From: tharvik Date: Wed, 11 May 2016 13:40:22 +0200 Subject: [PATCH 4/5] add conditional fix for io --- stdlib/3/io.pyi | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 64743b377d6a..22c9bcb9e0bd 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -17,13 +17,19 @@ if sys.version_info >= (3, 1): open = builtins.open -if sys.version_info >= (3, 3): - BlockingIOError = BlockingIOError - class UnsupportedOperation(OSError, ValueError): ... -else: - class BlockingIOError(IOError): - characters_written = ... # type: int - class UnsupportedOperation(IOError, ValueError): ... +# FIXME when mypy handle condtional, we can uncomment the next block and remove +# the temporary fix +#if sys.version_info >= (3, 3): +# BlockingIOError = BlockingIOError +# class UnsupportedOperation(OSError, ValueError): ... +#else: +# class BlockingIOError(IOError): +# characters_written = ... # type: int +# class UnsupportedOperation(IOError, ValueError): ... +class BlockingIOError(OSError): + characters_written = ... # type: int +class UnsupportedOperation(OSError, ValueError): ... + class IOBase: def __iter__(self) -> Iterator[bytes]: ... From 298d908f702792516a0b83e6c15ce786c51e9488 Mon Sep 17 00:00:00 2001 From: tharvik Date: Wed, 11 May 2016 18:09:12 +0200 Subject: [PATCH 5/5] remove support for python 3.{0,1} in io --- stdlib/3/io.pyi | 91 ++++++++++++------------------------------------- 1 file changed, 22 insertions(+), 69 deletions(-) diff --git a/stdlib/3/io.pyi b/stdlib/3/io.pyi index 22c9bcb9e0bd..bcb924c39517 100644 --- a/stdlib/3/io.pyi +++ b/stdlib/3/io.pyi @@ -10,10 +10,9 @@ from types import TracebackType DEFAULT_BUFFER_SIZE = ... # type: int -if sys.version_info >= (3, 1): - SEEK_SET = ... # type: int - SEEK_CUR = ... # type: int - SEEK_END = ... # type: int +SEEK_SET = ... # type: int +SEEK_CUR = ... # type: int +SEEK_END = ... # type: int open = builtins.open @@ -46,6 +45,9 @@ class IOBase: def seek(self, offset: int, whence: int = ...) -> int: ... def seekable(self) -> bool: ... def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def writelines(self, lines: bytes) -> None: ... if sys.version_info >= (3, 4): def readline(self, size: int = ...) -> bytes: ... def __del__(self) -> None: ... @@ -55,28 +57,18 @@ class IOBase: closed = ... # type: bool else: def closed(self) -> bool: ... # type: ignore - if sys.version_info >= (3, 1): - def truncate(self, size: Optional[int] = ...) -> int: ... - else: - def truncate(self, size: int = ...) -> int: ... - if sys.version_info >= (3, 1): - def writable(self) -> bool: ... - def writelines(self, lines: bytes) -> None: ... class RawIOBase(IOBase): def readall(self) -> bytes: ... + def readinto(self, b: bytearray) -> Optional[int]: ... + def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... if sys.version_info >= (3, 4): def read(self, size: int = ...) -> Optional[bytes]: ... else: def read(self, n: int = ...) -> Optional[bytes]: ... # type: ignore - if sys.version_info >= (3, 1): - def readinto(self, b: bytearray) -> Optional[int]: ... - def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... - else: - def readinto(self, b: bytearray) -> int: ... - def write(self, b: Union[bytes, bytearray]) -> int: ... class BufferedIOBase(IOBase): + def detach(self) -> 'RawIOBase': ... def readinto(self, b: bytearray) -> int: ... def write(self, b: Union[bytes, bytearray]) -> int: ... if sys.version_info >= (3, 5): @@ -84,11 +76,9 @@ class BufferedIOBase(IOBase): if sys.version_info >= (3, 4): def read(self, size: Optional[int] = ...) -> bytes: ... def read1(self, size: int = ...) -> bytes: ... - elif sys.version_info >= (3, 1): + else: def read(self, n: Optional[int] = ...) -> bytes: ... # type: ignore def read1(self, n: int = ...) -> bytes: ... # type: ignore - if sys.version_info >= (3, 1): - def detach(self) -> 'RawIOBase': ... class FileIO(RawIOBase): @@ -100,25 +90,16 @@ class FileIO(RawIOBase): opener: Optional[ Callable[[Union[int, str], str], int]] = ...) \ -> None: ... - elif sys.version_info >= (3, 1): + else: def __init__(self, name: Union[str, bytes, int], # type: ignore mode: str = ..., closefd: bool = ...) -> None: ... - else: - def __init__(self, name: str, # type: ignore - mode: str = ...) -> None: ... class BytesIO(BufferedIOBase): - if sys.version_info >= (3, 1): - def __init__(self, initial_bytes: bytes = ...) -> None: ... - else: - def __init__(self, # type: ignore - initial_bytes: bytearray = ...) -> None: ... + def __init__(self, initial_bytes: bytes = ...) -> None: ... def getvalue(self) -> bytes: ... if sys.version_info >= (3, 2): def getbuffer(self) -> memoryview: ... - if sys.version_info < (3, 1): - def read1(self) -> bytes: ... # type: ignore class BufferedReader(BufferedIOBase): def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... @@ -126,46 +107,30 @@ class BufferedReader(BufferedIOBase): def peek(self, size: int = ...) -> bytes: ... else: def peek(self, n: int = ...) -> bytes: ... # type: ignore - if sys.version_info < (3, 1): - def read1(self, n: int = ...) -> bytes: ... class BufferedWriter(BufferedIOBase): - if sys.version_info >= (3, 1): - def __init__(self, raw: RawIOBase, - buffer_size: int = ...) -> None: ... - else: - def __init__(self, raw: RawIOBase, # type: ignore - buffer_size: int = ..., max_buffer_size: int = ...) \ - -> None: ... + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def flush(self) -> None: ... def write(self, b: Union[bytes, bytearray]) -> int: ... class BufferedRandom(BufferedReader, BufferedWriter): - if sys.version_info >= (3, 1): - def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... - def seek(self, offset: int, whence: int = ...) -> int: ... - def tell(self) -> int: ... - else: - def __init__(self, raw: RawIOBase, # type: ignore - buffer_size: int = ..., max_buffer_size: int = ...) \ - -> None: ... + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def tell(self) -> int: ... class BufferedRWPair(BufferedIOBase): - if sys.version_info >= (3, 1): - def __init__(self, reader: RawIOBase, writer: RawIOBase, - buffer_size: int = ...) -> None: ... - else: - def __init__(self, reader: RawIOBase, writer: RawIOBase, # type: ignore - buffer_size: int = ..., max_buffer_size: int = ...) \ - -> None: ... + def __init__(self, reader: RawIOBase, writer: RawIOBase, + buffer_size: int = ...) -> None: ... class TextIOBase(IOBase): encoding = ... # type: str + errors = ... # type: Optional[str] newlines = ... # type: Union[str, Tuple[str, ...], None] def __iter__(self) -> Iterator[str]: ... # type: ignore def __next__(self) -> str: ... # type: ignore def __enter__(self) -> 'TextIOBase': ... + def detach(self) -> IOBase: ... def write(self, s: str) -> int: ... if sys.version_info >= (3, 4): def readline(self, size: int = ...) -> str: ... # type: ignore @@ -177,11 +142,6 @@ class TextIOBase(IOBase): if sys.version_info >= (3, 2): def seek(self, offset: int, whence: int = ...) -> int: ... def tell(self) -> int: ... - if sys.version_info >= (3, 1): - errors = ... # type: Optional[str] - def detach(self) -> IOBase: ... - else: - def read(self, n: Optional[int] = ...) -> str: ... # type: ignore class TextIOWrapper(TextIOBase): line_buffering = ... # type: bool @@ -195,17 +155,10 @@ class TextIOWrapper(TextIOBase): encoding: str = ..., errors: Optional[str] = ..., newline: Optional[str] = ..., line_buffering: bool = ...) \ -> None: ... - if sys.version_info < (3, 1): - errors = ... # type: Optional[str] class StringIO(TextIOWrapper): - if sys.version_info >= (3, 1): - def __init__(self, initial_value: str = ..., - newline: Optional[str] = ...) -> None: ... - else: - def __init__(self, initial_value: str = ..., # type: ignore - encoding: str = ..., errors: Optional[str] = ..., - newline: Optional[str] = ...) -> None: ... + def __init__(self, initial_value: str = ..., + newline: Optional[str] = ...) -> None: ... def getvalue(self) -> str: ... class IncrementalNewlineDecoder(codecs.IncrementalDecoder): ...