From 9a0dfe7f4235e849e0e7976df14aa97f4a850faa Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Thu, 13 Apr 2017 16:19:52 -0400 Subject: [PATCH 1/3] a better definition for io.IOBase --- stdlib/2/io.pyi | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdlib/2/io.pyi b/stdlib/2/io.pyi index 330b9843a124..f725e82d21b9 100644 --- a/stdlib/2/io.pyi +++ b/stdlib/2/io.pyi @@ -5,6 +5,7 @@ # Only a subset of functionality is included. from typing import List, BinaryIO, TextIO, IO, overload, Iterator, Iterable, Any, Union, Optional +import _io DEFAULT_BUFFER_SIZE = 0 @@ -13,9 +14,7 @@ def open(file: Union[str, unicode, int], errors: unicode = ..., newline: unicode = ..., closefd: bool = ...) -> IO[Any]: ... -class IOBase: - # TODO - ... +class IOBase(BinaryIO, _io._IOBase): ... class BytesIO(BinaryIO): def __init__(self, initial_bytes: str = ...) -> None: ... From 79e7706e396fdc4b675d178725ea9ffa883b4d0c Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Thu, 13 Apr 2017 16:24:52 -0400 Subject: [PATCH 2/3] move BinaryIO superclass into _io._IOBase --- stdlib/2/_io.pyi | 22 ++-------------------- stdlib/2/io.pyi | 2 +- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/stdlib/2/_io.pyi b/stdlib/2/_io.pyi index e85da33176c4..f5fc1f0a127b 100644 --- a/stdlib/2/_io.pyi +++ b/stdlib/2/_io.pyi @@ -1,4 +1,4 @@ -from typing import Any, Optional, Iterable, Tuple, List, Union +from typing import Any, BinaryIO, Optional, Iterable, Tuple, List, Union DEFAULT_BUFFER_SIZE = ... # type: int @@ -9,29 +9,11 @@ class BlockingIOError(IOError): class UnsupportedOperation(ValueError, IOError): ... -class _IOBase(object): - closed = ... # type: bool - def __enter__(self) -> "_IOBase": ... - def __exit__(self, type, value, traceback) -> bool: ... - def __iter__(self) -> "_IOBase": ... +class _IOBase(BinaryIO): def _checkClosed(self) -> None: ... def _checkReadable(self) -> None: ... def _checkSeekable(self) -> None: ... def _checkWritable(self) -> None: ... - def close(self) -> None: ... - def fileno(self) -> int: ... - def flush(self) -> None: ... - def isatty(self) -> bool: ... - def next(self) -> str: ... - def readable(self) -> bool: ... - def readline(self, limit: int = ...) -> str: ... - def readlines(self, hint: int = ...) -> List[str]: ... - def seek(self, offset: int, whence: int = ...) -> None: ... - def seekable(self) -> bool: ... - def tell(self) -> int: ... - def truncate(self, size: int = ...) -> int: ... - def writable(self) -> bool: ... - def writelines(self, lines: Iterable[str]) -> None: ... class _BufferedIOBase(_IOBase): def read1(self, n: int) -> str: ... diff --git a/stdlib/2/io.pyi b/stdlib/2/io.pyi index f725e82d21b9..18bf7b5938d5 100644 --- a/stdlib/2/io.pyi +++ b/stdlib/2/io.pyi @@ -14,7 +14,7 @@ def open(file: Union[str, unicode, int], errors: unicode = ..., newline: unicode = ..., closefd: bool = ...) -> IO[Any]: ... -class IOBase(BinaryIO, _io._IOBase): ... +class IOBase(_io._IOBase): ... class BytesIO(BinaryIO): def __init__(self, initial_bytes: str = ...) -> None: ... From a8a5cf7f83dd0da9ca3d925b76242a326d178d0a Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Thu, 13 Apr 2017 16:41:13 -0400 Subject: [PATCH 3/3] remove write() from _TextIOBase --- stdlib/2/_io.pyi | 2 -- 1 file changed, 2 deletions(-) diff --git a/stdlib/2/_io.pyi b/stdlib/2/_io.pyi index f5fc1f0a127b..6e144bcf67eb 100644 --- a/stdlib/2/_io.pyi +++ b/stdlib/2/_io.pyi @@ -69,8 +69,6 @@ class _TextIOBase(_IOBase): newlines = ... # type: Union[str, unicode] encoding = ... # type: Optional[str] def read(self, n: int = ...) -> str: ... - def write(self) -> None: - raise UnsupportedOperation def detach(self) -> None: raise UnsupportedOperation