mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-10 05:51:52 +08:00
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:
committed by
Jelle Zijlstra
parent
6fe68fd120
commit
c4e0580a4a
121
stdlib/2/_io.pyi
121
stdlib/2/_io.pyi
@@ -1,15 +1,18 @@
|
||||
from typing import Any, BinaryIO, IO, Iterable, Iterator, List, Optional, Type, Tuple, Union
|
||||
from typing import Any, AnyStr, BinaryIO, IO, Text, TextIO, Iterable, Iterator, List, Optional, Type, Tuple, TypeVar, Union
|
||||
from types import TracebackType
|
||||
|
||||
DEFAULT_BUFFER_SIZE = ... # type: int
|
||||
|
||||
|
||||
class BlockingIOError(IOError):
|
||||
characters_written = ... # type: int
|
||||
|
||||
class UnsupportedOperation(ValueError, IOError): ...
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
class _IOBase(BinaryIO):
|
||||
@property
|
||||
def closed(self) -> bool: ...
|
||||
def _checkClosed(self) -> None: ...
|
||||
def _checkReadable(self) -> None: ...
|
||||
def _checkSeekable(self) -> None: ...
|
||||
@@ -19,91 +22,147 @@ class _IOBase(BinaryIO):
|
||||
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 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: bytes) -> int: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> bool: ...
|
||||
def __iter__(self: _T) -> _T: ...
|
||||
# The parameter type of writelines[s]() is determined by that of write():
|
||||
def writelines(self, lines: Iterable[bytes]) -> None: ...
|
||||
# The return type of readline[s]() and next() is determined by that of read():
|
||||
def readline(self, limit: int = ...) -> bytes: ...
|
||||
def readlines(self, hint: int = ...) -> list[bytes]: ...
|
||||
def next(self) -> bytes: ...
|
||||
def __iter__(self) -> Iterator[bytes]: ...
|
||||
def __enter__(self) -> '_IOBase': ...
|
||||
def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException],
|
||||
# TODO: traceback should be TracebackType but that's defined in types
|
||||
traceback: Optional[Any]) -> bool: ...
|
||||
|
||||
class _BufferedIOBase(_IOBase):
|
||||
def read1(self, n: int) -> str: ...
|
||||
def read(self, n: int = ...) -> str: ...
|
||||
def read1(self, n: int) -> bytes: ...
|
||||
def read(self, size: int = ...) -> bytes: ...
|
||||
def readinto(self, buffer: bytearray) -> int: ...
|
||||
def write(self, s: str) -> int: ...
|
||||
def detach(self) -> "_BufferedIOBase": ...
|
||||
def write(self, s: bytes) -> int: ...
|
||||
def detach(self) -> _IOBase: ...
|
||||
|
||||
class BufferedRWPair(_BufferedIOBase):
|
||||
def peek(self, n: int = ...) -> str: ...
|
||||
def __init__(self, reader: _RawIOBase, writer: _RawIOBase,
|
||||
buffer_size: int = ..., max_buffer_size: int = ...) -> None: ...
|
||||
def peek(self, n: int = ...) -> bytes: ...
|
||||
def __enter__(self) -> BufferedRWPair: ...
|
||||
|
||||
class BufferedRandom(_BufferedIOBase):
|
||||
mode = ... # type: str
|
||||
name = ... # type: str
|
||||
raw = ... # type: _IOBase
|
||||
mode = ... # type: str
|
||||
def peek(self, n: int = ...) -> str: ...
|
||||
def __init__(self, raw: _IOBase,
|
||||
buffer_size: int = ...,
|
||||
max_buffer_size: int = ...) -> None: ...
|
||||
def peek(self, n: int = ...) -> bytes: ...
|
||||
|
||||
class BufferedReader(_BufferedIOBase):
|
||||
mode = ... # type: str
|
||||
name = ... # type: str
|
||||
raw = ... # type: _IOBase
|
||||
mode = ... # type: str
|
||||
def peek(self, n: int = ...) -> str: ...
|
||||
def __init__(self, raw: _IOBase, buffer_size: int = ...) -> None: ...
|
||||
def peek(self, n: int = ...) -> bytes: ...
|
||||
|
||||
class BufferedWriter(_BufferedIOBase):
|
||||
name = ... # type: str
|
||||
raw = ... # type: _IOBase
|
||||
mode = ... # type: str
|
||||
def __init__(self, raw: _IOBase,
|
||||
buffer_size: int = ...,
|
||||
max_buffer_size: int = ...) -> None: ...
|
||||
|
||||
class BytesIO(_BufferedIOBase):
|
||||
def __init__(self, initial_bytes: bytes = ...) -> None: ...
|
||||
def __setstate__(self, tuple) -> None: ...
|
||||
def __getstate__(self) -> tuple: ...
|
||||
def getvalue(self) -> str: ...
|
||||
def getvalue(self) -> bytes: ...
|
||||
def write(self, s: bytes) -> int: ...
|
||||
def writelines(self, lines: Iterable[bytes]) -> None: ...
|
||||
def read1(self, size: int) -> bytes: ...
|
||||
def next(self) -> bytes: ...
|
||||
|
||||
class _RawIOBase(_IOBase):
|
||||
def readall(self) -> str: ...
|
||||
def read(self, n: int = ...) -> str: ...
|
||||
|
||||
class FileIO(_RawIOBase):
|
||||
class FileIO(_RawIOBase, BytesIO): # type: ignore # for __enter__
|
||||
mode = ... # type: str
|
||||
closefd = ... # type: bool
|
||||
def __init__(self, file: str, mode: str = ...) -> None: ...
|
||||
def readinto(self, buffer: bytearray)-> int: ...
|
||||
def write(self, pbuf: str) -> int: ...
|
||||
|
||||
class IncrementalNewlineDecoder(object):
|
||||
newlines = ... # type: Union[str, unicode]
|
||||
def __init__(self, decoder, translate, z=...) -> None: ...
|
||||
def decode(self, input, final) -> Any: ...
|
||||
def getstate(self) -> Tuple[Any, int]: ...
|
||||
def setstate(self, state: Tuple[Any, int]) -> None: ...
|
||||
def reset(self) -> None: ...
|
||||
|
||||
class _TextIOBase(_IOBase):
|
||||
|
||||
# Note: In the actual _io.py, _TextIOBase inherits from _IOBase.
|
||||
class _TextIOBase(TextIO):
|
||||
errors = ... # type: Optional[str]
|
||||
newlines = ... # type: Union[str, unicode]
|
||||
encoding = ... # type: Optional[str]
|
||||
def read(self, n: int = ...) -> str: ...
|
||||
def detach(self) -> None:
|
||||
raise UnsupportedOperation
|
||||
# TODO: On _TextIOBase, this is always None. But it's unicode/bytes in subclasses.
|
||||
newlines = ... # type: Union[None, unicode, bytes]
|
||||
encoding = ... # type: str
|
||||
@property
|
||||
def closed(self) -> bool: ...
|
||||
def _checkClosed(self) -> None: ...
|
||||
def _checkReadable(self) -> None: ...
|
||||
def _checkSeekable(self) -> None: ...
|
||||
def _checkWritable(self) -> None: ...
|
||||
def close(self) -> None: ...
|
||||
def detach(self) -> IO: ...
|
||||
def fileno(self) -> int: ...
|
||||
def flush(self) -> None: ...
|
||||
def isatty(self) -> bool: ...
|
||||
def next(self) -> unicode: ...
|
||||
def read(self, size: 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, pbuf: unicode) -> int: ...
|
||||
def writelines(self, lines: Iterable[unicode]) -> None: ...
|
||||
def __enter__(self: _T) -> _T: ...
|
||||
def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[Any]) -> bool: ...
|
||||
def __iter__(self: _T) -> _T: ...
|
||||
|
||||
class StringIO(_TextIOBase):
|
||||
line_buffering = ... # type: bool
|
||||
def getvalue(self) -> str: ...
|
||||
def __init__(self,
|
||||
initial_value: Optional[unicode] = ...,
|
||||
newline: Optional[unicode] = ...) -> None: ...
|
||||
def __setstate__(self, state: tuple) -> None: ...
|
||||
def __getstate__(self) -> tuple: ...
|
||||
def getvalue(self) -> unicode: ...
|
||||
|
||||
class TextIOWrapper(_TextIOBase):
|
||||
name = ... # type: str
|
||||
line_buffering = ... # type: bool
|
||||
buffer = ... # type: str
|
||||
buffer = ... # type: BinaryIO
|
||||
_CHUNK_SIZE = ... # type: int
|
||||
def __init__(self, buffer: IO,
|
||||
encoding: Optional[Text] = ...,
|
||||
errors: Optional[Text] = ...,
|
||||
newline: Optional[Text] = ...,
|
||||
line_buffering: bool = ...,
|
||||
write_through: bool = ...) -> None: ...
|
||||
|
||||
def open(file: Union[int, str], mode: str = ...) -> _IOBase: ...
|
||||
def open(file: Union[str, unicode, int],
|
||||
mode: unicode = ...,
|
||||
buffering: int = ...,
|
||||
encoding: Optional[Text] = ...,
|
||||
errors: Optional[Text] = ...,
|
||||
newline: Optional[Text] = ...,
|
||||
closefd: bool = ...) -> IO[Any]: ...
|
||||
|
||||
111
stdlib/2/io.pyi
111
stdlib/2/io.pyi
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user