10000 fix integration of io with mypy (#196) · python/typeshed@e9efb31 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9efb31

Browse files
tharvikgvanrossum
authored andcommitted
fix integration of io with mypy (#196)
1 parent 5c881a6 commit e9efb31

File tree

1 file changed

+102
-15
lines changed

1 file changed

+102
-15
lines changed

stdlib/3/io.pyi

Lines changed: 102 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Stubs for io
22

33
from typing import (
4-
List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, Tuple
4+
List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, Tuple, Any, IO
55
)
66
import builtins
77
import codecs
@@ -47,7 +47,7 @@ class IOBase:
4747
def tell(self) -> int: ...
4848
def truncate(self, size: Optional[int] = ...) -> int: ...
4949
def writable(self) -> bool: ...
50-
def writelines(self, lines: bytes) -> None: ...
50+
def writelines(self, lines: List[Union[bytes, bytearray]]) -> None: ...
5151
if sys.version_info >= (3, 4):
5252
def readline(self, size: int = ...) -> bytes: ...
5353
def __del__(self) -> None: ...
@@ -68,7 +68,7 @@ class RawIOBase(IOBase):
6868
def read(self, n: int = ...) -> Optional[bytes]: ... # type: ignore
6969

7070
class BufferedIOBase(IOBase):
71-
def detach(self) -> 'RawIOBase': ...
71+
def detach(self) -> RawIOBase: ...
7272
def readinto(self, b: bytearray) -> int: ...
7373
def write(self, b: Union[bytes, bytearray]) -> int: ...
7474
if sys.version_info >= (3, 5):
@@ -94,12 +94,53 @@ class FileIO(RawIOBase):
9494
def __init__(self, name: Union[str, bytes, int], # type: ignore
9595
mode: str = ..., closefd: bool = ...) -> None: ...
9696

97-
98-
class BytesIO(BufferedIOBase):
97+
# TODO should extend from BufferedIOBase
98+
class BytesIO(BinaryIO):
9999
def __init__(self, initial_bytes: bytes = ...) -> None: ...
100100
def getvalue(self) -> bytes: ...
101101
if sys.version_info >= (3, 2):
102102
def getbuffer(self) -> memoryview: ...
103+
# copied from IOBase
104+
def __iter__(self) -> Iterator[bytes]: ...
105+
def __next__(self) -> bytes: ...
106+
def __enter__(self) -> 'BytesIO': ...
107+
def __exit__(self, t: type = None, value: BaseException = None,
108+
traceback: Any = None) -> bool: ...
109+
def close(self) -> None: ...
110+
def fileno(self) -> int: ...
111+
def flush(self) -> None: ...
112+
def isatty(self) -> bool: ...
113+
def readable(self) -> bool: ...
114+
def readlines(self, hint: int = ...) -> List[bytes]: ...
115+
def seek(self, offset: int, whence: int = ...) -> int: ...
116+
def seekable(self) -> bool: ...
117+
def tell(self) -> int: ...
118+
def truncate(self, size: Optional[int] = ...) -> int: ...
119+
def writable(self) -> bool: ...
120+
# TODO should be the next line instead
121+
# def writelines(self, lines: List[Union[bytes, bytearray]]) -> None: ...
122+
def writelines(self, lines: Any) -> None: ...
123+
if sys.version_info >= (3, 4):
124+
def readline(self, size: int = ...) -> bytes: ...
125+
def __del__(self) -> None: ...
126+
else:
127+
def readline(self, limit: int = ...): ... # type: ignore
128+
if sys.version_info >= (3, 2):
129+
closed = ... # type: bool
130+
else:
131+
def closed(self) -> bool: ... # type: ignore
132+
# copied from BufferedIOBase
133+
def detach(self) -> RawIOBase: ...
134+
def readinto(self, b: bytearray) -> int: ...
135+
def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ...
136+
if sys.version_info >= (3, 5):
137+
def readinto1(self, b: bytearray) -> int: ...
138+
if sys.version_info >= (3, 4):
139+
def read(self, size: Optional[int] = ...) -> bytes: ...
140+
def read1(self, size: int = ...) -> bytes: ...
141+
else:
142+
def read(self, n: Optional[int] = ...) -> bytes: ... # type: ignore
143+
def read1(self, n: int = ...) -> bytes: ... # type: ignore
103144

104145
class BufferedReader(BufferedIOBase):
105146
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
@@ -143,18 +184,64 @@ class TextIOBase(IOBase):
143184
def seek(self, offset: int, whence: int = ...) -> int: ...
144185
def tell(self) -> int: ...
145186

146-
class TextIOWrapper(TextIOBase):
187+
# TODO should extend from TextIOBase
188+
class TextIOWrapper(TextIO):
147189
line_buffering = ... # type: bool
148-
if sys.version_info >= (3, 3):
149-
def __init__(self, buffer: BufferedIOBase, encoding: str = ...,
150-
errors: Optional[str] = ..., newline: Optional[str] = ...,
151-
line_buffering: bool = ..., write_through: bool = ...) \
152-
-> None: ...
190+
# TODO uncomment after fixing mypy about using write_through
191+
#if sys.version_info >= (3, 3):
192+
# def __init__(self, buffer: IO[bytes], encoding: str = ...,
193+
# errors: Optional[str] = ..., newline: Optional[str] = ...,
194+
# line_buffering: bool = ..., write_through: bool = ...) \
195+
# -> None: ...
196+
#else:
197+
# def __init__(self, buffer: IO[bytes], # type: ignore
198+
# encoding: str = ..., errors: Optional[str] = ...,
199+
# newline: Optional[str] = ..., line_buffering: bool = ...) \
200+
# -> None: ...
201+
def __init__(self, buffer: IO[bytes], encoding: str = ...,
202+
errors: Optional[str] = ..., newline: Optional[str] = ...,
203+
line_buffering: bool = ..., write_through: bool = ...) \
204+
-> None: ...
205+
# copied from IOBase
206+
def __exit__(self, t: type = None, value: BaseException = None,
207+
traceback: Any = None) -> bool: ...
208+
def close(self) -> None: ...
209+
def fileno(self) -> int: ...
210+
def flush(self) -> None: ...
211+
def isatty(self) -> bool: ...
212+
def readable(self) -> bool: ...
213+
def readlines(self, hint: int = ...) -> List[str]: ...
214+
def seekable(self) -> bool: ...
215+
def truncate(self, size: Optional[int] = ...) -> int: ...
216+
def writable(self) -> bool: ...
217+
# TODO should be the next line instead
218+
# def writelines(self, lines: List[str]) -> None: ...
219+
def writelines(self, lines: Any) -> None: ...
220+
if sys.version_info >= (3, 4):
221+
def __del__(self) -> None: ...
222+
if sys.version_info >= (3, 2):
223+
closed = ... # type: bool
153224
else:
154-
def __init__(self, buffer: BufferedIOBase, # type: ignore
155-
encoding: str = ..., errors: Optional[str] = ...,
156-
newline: Optional[str] = ..., line_buffering: bool = ...) \
157-
-> None: ...
225+
def closed(self) -> bool: ... # type: ignore
226+
# copied from TextIOBase
227+
encoding = ... # type: str
228+
errors = ... # type: Optional[str]
229+
newlines = ... # type: Union[str, Tuple[str, ...], None]
230+
def __iter__(self) -> Iterator[str]: ... # type: ignore
231+
def __next__(self) -> str: ... # type: ignore
232+
def __enter__(self) -> 'TextIO': ...
233+
def detach(self) -> IOBase: ...
234+
def write(self, s: str) -> int: ...
235+
if sys.version_info >= (3, 4):
236+
def readline(self, size: int = ...) -> str: ... # type: ignore
237+
def read(self, size: Optional[int] = ...) -> str: ...
238+
elif sys.version_info >= (3, 2):
239+
def readline(self, limit: int = ...) -> str: ... # type: ignore
240+
else:
241+
def readline(self) -> str: ... # type: ignore
242+
if sys.version_info >= (3, 2):
243+
def seek(self, offset: int, whence: int = ...) -> int: ...
244+
def tell(self) -> int: ...
158245

159246
class StringIO(TextIOWrapper):
160247
def __init__(self, initial_value: str = ...,

0 commit comments

Comments
 (0)
0