1
1
from typing import (
2
- List , BinaryIO , TextIO , Iterator , Union , Optional , Callable , Tuple , Type , Any , IO , Iterable
2
+ List , BinaryIO , TextIO , Iterator , Union , Optional , Callable , Tuple , Type , Any , IO , Iterable , TypeVar
3
3
)
4
4
import builtins
5
5
import codecs
6
6
import sys
7
7
from mmap import mmap
8
8
from types import TracebackType
9
- from typing import TypeVar
10
9
11
10
if sys .version_info >= (3 , 8 ):
12
11
from typing import Literal
@@ -85,16 +84,20 @@ class BufferedIOBase(IOBase):
85
84
def read (self , __size : Optional [int ] = ...) -> bytes : ...
86
85
def read1 (self , __size : int = ...) -> bytes : ...
87
86
88
- class FileIO (RawIOBase ):
87
+ class FileIO (RawIOBase , BinaryIO ):
89
88
mode : str
90
- name : Union [int , str ]
89
+ # Technically this is whatever is passed in as file, either a str, a bytes, or an int.
90
+ name : Union [int , str ] # type: ignore
91
91
def __init__ (
92
92
self ,
93
93
file : Union [str , bytes , int ],
94
94
mode : str = ...,
95
95
closefd : bool = ...,
96
96
opener : Optional [Callable [[Union [int , str ], str ], int ]] = ...
97
97
) -> None : ...
98
+ def write (self , __b : bytes ) -> int : ...
99
+ def read (self , __size : int = ...) -> bytes : ...
100
+ def __enter__ (self : _T ) -> _T : ...
98
101
99
102
class BytesIO (BufferedIOBase , BinaryIO ):
100
103
def __init__ (self , initial_bytes : bytes = ...) -> None : ...
@@ -110,23 +113,24 @@ class BytesIO(BufferedIOBase, BinaryIO):
110
113
else :
111
114
def read1 (self , __size : Optional [int ]) -> bytes : ... # type: ignore
112
115
113
- class BufferedReader (BufferedIOBase ):
116
+ class BufferedReader (BufferedIOBase , BinaryIO ):
117
+ def __enter__ (self : _T ) -> _T : ...
114
118
def __init__ (self , raw : RawIOBase , buffer_size : int = ...) -> None : ...
115
119
def peek (self , __size : int = ...) -> bytes : ...
116
120
if sys .version_info >= (3 , 7 ):
117
121
def read1 (self , __size : int = ...) -> bytes : ...
118
122
else :
119
123
def read1 (self , __size : int ) -> bytes : ... # type: ignore
120
124
121
- class BufferedWriter (BufferedIOBase ):
125
+ class BufferedWriter (BufferedIOBase , BinaryIO ):
126
+ def __enter__ (self : _T ) -> _T : ...
122
127
def __init__ (self , raw : RawIOBase , buffer_size : int = ...) -> None : ...
123
- def flush (self ) -> None : ...
124
128
def write (self , __buffer : Union [bytes , bytearray ]) -> int : ...
125
129
126
130
class BufferedRandom (BufferedReader , BufferedWriter ):
131
+ def __enter__ (self : _T ) -> _T : ...
127
132
def __init__ (self , raw : RawIOBase , buffer_size : int = ...) -> None : ...
128
133
def seek (self , __target : int , __whence : int = ...) -> int : ...
129
- def tell (self ) -> int : ...
130
134
if sys .version_info >= (3 , 7 ):
131
135
def read1 (self , __size : int = ...) -> bytes : ...
132
136
else :
@@ -144,25 +148,18 @@ class TextIOBase(IOBase):
144
148
def __iter__ (self ) -> Iterator [str ]: ... # type: ignore
145
149
def __next__ (self ) -> str : ... # type: ignore
146
150
def detach (self ) -> BinaryIO : ...
147
- def write (self , s : str ) -> int : ...
151
+ def write (self , __s : str ) -> int : ...
148
152
def writelines (self , __lines : List [str ]) -> None : ... # type: ignore
149
- def readline (self , size : int = ...) -> str : ... # type: ignore
153
+ def readline (self , __size : int = ...) -> str : ... # type: ignore
150
154
def readlines (self , __hint : int = ...) -> List [str ]: ... # type: ignore
151
- def read (self , size : Optional [int ] = ...) -> str : ...
152
- def seek (self , offset : int , whence : int = ...) -> int : ...
155
+ def read (self , __size : Optional [int ] = ...) -> str : ...
153
156
def tell (self ) -> int : ...
154
157
155
- # TODO should extend from TextIOBase
156
- class TextIOWrapper (TextIO ):
158
+ class TextIOWrapper (TextIOBase , TextIO ):
157
159
line_buffering : bool
158
- # TODO uncomment after fixing mypy about using write_through
159
- # def __init__(self, buffer: IO[bytes], encoding: str = ...,
160
- # errors: Optional[str] = ..., newline: Optional[str] = ...,
161
- # line_buffering: bool = ..., write_through: bool = ...) \
162
- # -> None: ...
163
160
def __init__ (
164
161
self ,
165
- buffer : BinaryIO ,
162
+ buffer : IO [ bytes ] ,
166
163
encoding : Optional [str ] = ...,
167
164
errors : Optional [str ] = ...,
168
165
newline : Optional [str ] = ...,
@@ -181,36 +178,15 @@ class TextIOWrapper(TextIO):
181
178
line_buffering : Optional [bool ] = ...,
182
179
write_through : Optional [bool ] = ...
183
180
) -> None : ...
184
- # copied from IOBase
185
- def __exit__ (self , t : Optional [Type [BaseException ]] = ..., value : Optional [BaseException ] = ...,
186
- traceback : Optional [TracebackType ] = ...) -> Optional [bool ]: ...
187
- def close (self ) -> None : ...
188
- def fileno (self ) -> int : ...
189
- def flush (self ) -> None : ...
190
- def isatty (self ) -> bool : ...
191
- def readable (self ) -> bool : ...
192
- def readlines (self , __hint : int = ...) -> List [str ]: ...
193
- def seekable (self ) -> bool : ...
194
- def truncate (self , __size : Optional [int ] = ...) -> int : ...
195
- def writable (self ) -> bool : ...
196
- # TODO should be the next line instead
197
- # def writelines(self, lines: List[str]) -> None: ...
198
- def writelines (self , __lines : Any ) -> None : ...
199
- def __del__ (self ) -> None : ...
200
181
closed : bool
201
- # copied from TextIOBase
202
- encoding : str
203
- errors : Optional [str ]
204
- newlines : Union [str , Tuple [str , ...], None ]
205
- def __iter__ (self ) -> Iterator [str ]: ...
206
- def __next__ (self ) -> str : ...
207
- def __enter__ (self ) -> TextIO : ...
208
- def detach (self ) -> BinaryIO : ...
209
- def write (self , __text : str ) -> int : ...
210
- def readline (self , __size : int = ...) -> str : ...
211
- def read (self , __size : Optional [int ] = ...) -> str : ...
182
+ # These are inherited from TextIOBase, but must exist in the stub to satisfy mypy.
183
+ def __enter__ (self : _T ) -> _T : ...
184
+ def __iter__ (self ) -> Iterator [str ]: ... # type: ignore
185
+ def __next__ (self ) -> str : ... # type: ignore
186
+ def writelines (self , __lines : List [str ]) -> None : ... # type: ignore
187
+ def readline (self , __size : int = ...) -> str : ... # type: ignore
188
+ def readlines (self , __hint : int = ...) -> List [str ]: ... # type: ignore
212
189
def seek (self , __cookie : int , __whence : int = ...) -> int : ...
213
- def tell (self ) -> int : ...
214
190
215
191
class StringIO (TextIOWrapper ):
216
192
def __init__ (self , initial_value : Optional [str ] = ...,
@@ -220,7 +196,6 @@ class StringIO(TextIOWrapper):
220
196
# as a read-only property on IO[].
221
197
name : Any
222
198
def getvalue (self ) -> str : ...
223
- def __enter__ (self ) -> StringIO : ...
224
199
225
200
class IncrementalNewlineDecoder (codecs .IncrementalDecoder ):
226
201
def __init__ (self , decoder : Optional [codecs .IncrementalDecoder ],
0 commit comments