1
1
# Stubs for io
2
2
3
3
from typing import (
4
- List , BinaryIO , TextIO , Iterator , Union , Optional , Callable , Tuple
4
+ List , BinaryIO , TextIO , Iterator , Union , Optional , Callable , Tuple , Any , IO
5
5
)
6
6
import builtins
7
7
import codecs
@@ -47,7 +47,7 @@ class IOBase:
47
47
def tell (self ) -> int : ...
48
48
def truncate (self , size : Optional [int ] = ...) -> int : ...
49
49
def writable (self ) -> bool : ...
50
- def writelines (self , lines : bytes ) -> None : ...
50
+ def writelines (self , lines : List [ Union [ bytes , bytearray ]] ) -> None : ...
51
51
if sys .version_info >= (3 , 4 ):
52
52
def readline (self , size : int = ...) -> bytes : ...
53
53
def __del__ (self ) -> None : ...
@@ -68,7 +68,7 @@ class RawIOBase(IOBase):
68
68
def read (self , n : int = ...) -> Optional [bytes ]: ... # type: ignore
69
69
70
70
class BufferedIOBase (IOBase ):
71
- def detach (self ) -> ' RawIOBase' : ...
71
+ def detach (self ) -> RawIOBase : ...
72
72
def readinto (self , b : bytearray ) -> int : ...
73
73
def write (self , b : Union [bytes , bytearray ]) -> int : ...
74
74
if sys .version_info >= (3 , 5 ):
@@ -94,12 +94,53 @@ class FileIO(RawIOBase):
94
94
def __init__ (self , name : Union [str , bytes , int ], # type: ignore
95
95
mode : str = ..., closefd : bool = ...) -> None : ...
96
96
97
-
98
- class BytesIO (BufferedIOBase ):
97
+ # TODO should extend from BufferedIOBase
98
+ class BytesIO (BinaryIO ):
99
99
def __init__ (self , initial_bytes : bytes = ...) -> None : ...
100
100
def getvalue (self ) -> bytes : ...
101
101
if sys .version_info >= (3 , 2 ):
102
102
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
103
144
104
145
class BufferedReader (BufferedIOBase ):
105
146
def __init__ (self , raw : RawIOBase , buffer_size : int = ...) -> None : ...
@@ -143,18 +184,64 @@ class TextIOBase(IOBase):
143
184
def seek (self , offset : int , whence : int = ...) -> int : ...
144
185
def tell (self ) -> int : ...
145
186
146
- class TextIOWrapper (TextIOBase ):
187
+ # TODO should extend from TextIOBase
188
+ class TextIOWrapper (TextIO ):
147
189
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
153
224
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 : ...
158
245
159
246
class StringIO (TextIOWrapper ):
160
247
def __init__ (self , initial_value : str = ...,
0 commit comments