make io.pyi import everything from _io.py(i), like io.py does (#1395)

* make io.pyi import _io.py(i), like io.py does
* make write/writelines take 'Any', on _IOBase
* Add missing constructors, fix inconsistencies.
* Also, as far as possible, try to simplify, by moving methods into base
classes.
* fix lint+mypy warnings
* add missing __enter__ methods
* make _IOBase inherit from BinaryIO
* make _TextIOBase not subclass _IOBase
This commit is contained in:
Matthias Kramm
2017-06-21 20:04:04 -07:00
committed by Jelle Zijlstra
parent 6fe68fd120
commit c4e0580a4a
2 changed files with 115 additions and 117 deletions

View File

@@ -7,98 +7,37 @@
from typing import List, BinaryIO, TextIO, IO, overload, Iterator, Iterable, Any, Union, Optional
import _io
DEFAULT_BUFFER_SIZE = 0
from _io import BlockingIOError as BlockingIOError
from _io import BufferedRWPair as BufferedRWPair
from _io import BufferedRandom as BufferedRandom
from _io import BufferedReader as BufferedReader
from _io import BufferedWriter as BufferedWriter
from _io import BytesIO as BytesIO
from _io import DEFAULT_BUFFER_SIZE as DEFAULT_BUFFER_SIZE
from _io import FileIO as FileIO
from _io import IncrementalNewlineDecoder as IncrementalNewlineDecoder
from _io import StringIO as StringIO
from _io import TextIOWrapper as TextIOWrapper
from _io import UnsupportedOperation as UnsupportedOperation
from _io import open as open
def open(file: Union[str, unicode, int],
def _OpenWrapper(file: Union[str, unicode, int],
mode: unicode = ..., buffering: int = ..., encoding: unicode = ...,
errors: unicode = ..., newline: unicode = ...,
closefd: bool = ...) -> IO[Any]: ...
SEEK_SET = ... # type: int
SEEK_CUR = ... # type: int
SEEK_END = ... # type: int
class IOBase(_io._IOBase): ...
class BytesIO(BinaryIO):
def __init__(self, initial_bytes: str = ...) -> None: ...
# TODO getbuffer
# TODO see comments in BinaryIO for missing functionality
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 = ...) -> 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 = ...) -> int: ...
def seekable(self) -> bool: ...
def tell(self) -> int: ...
def truncate(self, size: Optional[int] = ...) -> int: ...
def writable(self) -> bool: ...
def write(self, s: str) -> int: ...
def writelines(self, lines: Iterable[str]) -> None: ...
def getvalue(self) -> str: ...
def read1(self) -> str: ...
class RawIOBase(_io._RawIOBase, IOBase):
pass
def __iter__(self) -> Iterator[str]: ...
def next(self) -> str: ...
def __enter__(self) -> 'BytesIO': ...
def __exit__(self, type, value, traceback) -> bool: ...
class BufferedIOBase(_io._BufferedIOBase, IOBase):
pass
class StringIO(TextIO):
def __init__(self, initial_value: unicode = ...,
newline: unicode = ...) -> None: ...
# TODO see comments in BinaryIO for missing functionality
name = ... # type: str
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 = ...) -> unicode: ...
def readable(self) -> bool: ...
def readline(self, limit: int = ...) -> unicode: ...
def readlines(self, hint: int = ...) -> List[unicode]: ...
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 write(self, s: unicode) -> int: ...
def writelines(self, lines: Iterable[unicode]) -> None: ...
def getvalue(self) -> unicode: ...
def __iter__(self) -> Iterator[unicode]: ...
def next(self) -> unicode: ...
def __enter__(self) -> 'StringIO': ...
def __exit__(self, type, value, traceback) -> bool: ...
class TextIOWrapper(TextIO):
# write_through is undocumented but used by subprocess
def __init__(self, buffer: IO[str], encoding: unicode = ...,
errors: unicode = ..., newline: unicode = ...,
line_buffering: bool = ...,
write_through: bool = ...) -> None: ...
# TODO see comments in BinaryIO for missing functionality
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 = ...) -> unicode: ...
def readable(self) -> bool: ...
def readline(self, limit: int = ...) -> unicode: ...
def readlines(self, hint: int = ...) -> List[unicode]: ...
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 write(self, s: unicode) -> int: ...
def writelines(self, lines: Iterable[unicode]) -> None: ...
def __iter__(self) -> Iterator[unicode]: ...
def next(self) -> unicode: ...
def __enter__(self) -> StringIO: ...
def __exit__(self, type, value, traceback) -> bool: ...
class BufferedIOBase(_io._BufferedIOBase, IOBase): ...
class TextIOBase(_io._TextIOBase, IOBase): # type: ignore
pass