1
1
# Stubs for io
2
2
3
- # Based on http://docs.python.org/3.2/library/io.html
4
-
5
- from typing import List , BinaryIO , TextIO , IO , overload , Iterator , Iterable , Any
3
+ from typing import (
4
+ List , BinaryIO , TextIO , Iterator , Union , Optional , Callable , no_type_check
5
+ )
6
6
import builtins
7
7
import codecs
8
- import _io
8
+ from types import TracebackType
9
9
10
- DEFAULT_BUFFER_SIZE = 0 # type: int
10
+ DEFAULT_BUFFER_SIZE = ... # type: int
11
11
SEEK_SET = ... # type: int
12
12
SEEK_CUR = ... # type: int
13
13
SEEK_END = ... # type: int
@@ -17,134 +17,102 @@ open = builtins.open
17
17
class BlockingIOError (OSError ): ...
18
18
class UnsupportedOperation (ValueError , OSError ): ...
19
19
20
- class IncrementalNewlineDecoder (codecs .IncrementalDecoder ):
21
- newlines = ... # type: Any
22
- def __init__ (self , * args , ** kwargs ) -> None : ...
23
- def decode (self , input , final = ...): ...
24
- def getstate (self ): ...
25
- def reset (self ): ...
26
- def setstate (self , state ): ...
27
-
28
- class IOBase (_io ._IOBase ): ...
29
- class RawIOBase (_io ._RawIOBase , IOBase ): ...
30
- class BufferedIOBase (_io ._BufferedIOBase , IOBase ): ...
31
- class TextIOBase (_io ._TextIOBase , IOBase ): ...
32
-
33
- class FileIO (_io ._RawIOBase ):
34
- closefd = ... # type: Any
35
- mode = ... # type: Any
36
- def __init__ (self , name , mode = ..., closefd = ..., opener = ...) -> None : ...
37
- def readinto (self , b ): ...
38
- def write (self , b ): ...
39
-
40
- class BufferedReader (_io ._BufferedIOBase ):
41
- mode = ... # type: Any
42
- name = ... # type: Any
43
- raw = ... # type: Any
44
- def __init__ (self , raw , buffer_size = ...) -> None : ...
45
- def peek (self , size : int = ...): ...
46
-
47
- class BufferedWriter (_io ._BufferedIOBase ):
48
- mode = ... # type: Any
49
- name = ... # type: Any
50
- raw = ... # type: Any
51
- def __init__ (self , raw , buffer_size = ...) -> None : ...
52
-
53
- class BufferedRWPair (_io ._BufferedIOBase ):
54
- def __init__ (self , reader , writer , buffer_size = ...) -> None : ...
55
- def peek (self , size : int = ...): ...
56
-
57
- class BufferedRandom (_io ._BufferedIOBase ):
58
- mode = ... # type: Any
59
- name = ... # type: Any
60
- raw = ... # type: Any
61
- def __init__ (self , raw , buffer_size = ...) -> None : ...
62
- def peek (self , size : int = ...): ...
63
20
64
- class BytesIO (BinaryIO ):
65
- def __init__ (self , initial_bytes : bytes = ...) -> None : ...
66
- # TODO getbuffer
67
- # TODO see comments in BinaryIO for missing functionality
68
- def close (self ) -> None : ...
21
+ class IOBase :
69
22
@property
23
+ def close (self ) -> None : ...
70
24
def closed (self ) -> bool : ...
71
25
def fileno (self ) -> int : ...
72
26
def flush (self ) -> None : ...
73
27
def isatty (self ) -> bool : ...
74
- def read (self , n : int = ...) -> bytes : ...
75
28
def readable (self ) -> bool : ...
76
- def readline (self , limit : int = ...) -> bytes : ...
77
- def readlines (self , hint : int = ...) -> List [bytes ]: ...
29
+ def readline (self , size : int = ...) -> bytes : ...
30
+ def readlines (self , hint : int = ...) -> List [bytes ]: ...
78
31
def seek (self , offset : int , whence : int = ...) -> int : ...
79
32
def seekable (self ) -> bool : ...
80
33
def tell (self ) -> int : ...
81
34
def truncate (self , size : int = ...) -> int : ...
82
35
def writable (self ) -> bool : ...
83
- @overload
84
- def write (self , s : bytes ) -> int : ...
85
- @overload
86
- def write (self , s : bytearray ) -> int : ...
87
- def writelines (self , lines : Iterable [bytes ]) -> None : ...
88
- def getvalue (self ) -> bytes : ...
89
- def read1 (self ) -> str : ...
36
+ def writelines (self , lines : bytes ) -> None : ...
37
+ def __del__ (self ) -> None : ...
90
38
39
+ def __enter__ (self ) -> 'IOBase' : ...
40
+ def __exit__ (self , exc_type : Optional [type ], exc_val : Optional [Exception ],
41
+ exc_tb : Optional [TracebackType ]) -> bool : ...
91
42
def __iter__ (self ) -> Iterator [bytes ]: ...
92
- def __enter__ (self ) -> 'BytesIO' : ...
93
- def __exit__ (self , t : type = None , value : BaseException = None , traceback : Any = None ) -> bool : ...
43
+ def __next__ (self ) -> bytes : ...
94
44
95
- class StringIO (TextIO ):
96
- def __init__ (self , initial_value : str = ...,
97
- newline : str = ...) -> None : ...
98
- # TODO see comments in BinaryIO for missing functionality
99
- def close (self ) -> None : ...
100
- @property
101
- def closed (self ) -> bool : ...
102
- def fileno (self ) -> int : ...
45
+ class RawIOBase (IOBase ):
46
+ def read (self , size : int = ...) -> Optional [bytes ]: ...
47
+ def readall (self ) -> bytes : ...
48
+ def readinto (self , b : bytearray ) -> Optional [int ]: ...
49
+ def write (self , b : Union [bytes , bytearray ]) -> Optional [int ]: ...
50
+
51
+ class BufferedIOBase (IOBase ):
52
+ def detach (self ) -> 'RawIOBase' : ...
53
+ def read (self , size : Optional [int ] = ...) -> bytes : ...
54
+ def read1 (self , size : int = ...) -> bytes : ...
55
+ def readinto (self , b : bytearray ) -> int : ...
56
+ def write (self , b : Union [bytes , bytearray ]) -> int : ...
57
+
58
+
59
+ class FileIO (RawIOBase ):
60
+ mode = ... # type: str
61
+ name = ... # type: Union[int, str]
62
+ def __init__ (self , name : Union [int , str ], mode : str = ...,
63
+ closefd : bool = ...,
64
+ opener : Optional [Callable [[Union [int , str ], int ], Union [TextIO , BytesIO ]]] = ...) -> None : ...
65
+
66
+
67
+ class BytesIO (BinaryIO ):
68
+ def __init__ (self , initial_bytes : bytes = ...) -> None : ...
69
+ def getbuffer (self ) -> memoryview : ...
70
+ def getvalue (self ) -> bytes : ...
71
+ def read1 (self , size : int = ...) -> Optional [bytes ]: ...
72
+ def readinto1 (self , b : bytearray ) -> int : ...
73
+
74
+ class BufferedReader (BufferedIOBase ):
75
+ def __init__ (self , raw : RawIOBase , buffer_size : int = ...) -> None : ...
76
+ def peek (self , size : int = ...) -> bytes : ...
77
+ def read (self , size : int = ...) -> bytes : ...
78
+ def read1 (self , size : int = ...) -> bytes : ...
79
+
80
+ class BufferedWriter (BufferedIOBase ):
81
+ def __init__ (self , raw : RawIOBase , buffer_size : int = ...) -> None : ...
103
82
def flush (self ) -> None : ...
104
- def isatty (self ) -> bool : ...
105
- def read (self , n : int = ...) -> str : ...
106
- def readable (self ) -> bool : ...
107
- def readline (self , limit : int = ...) -> str : ...
108
- def readlines (self , hint : int = ...) -> List [str ]: ...
83
+ def write (self , b : Union [bytes , bytearray ]) -> int : ...
84
+
85
+ class BufferedRandom (BufferedReader , BufferedWriter ):
86
+ def __init__ (self , raw : RawIOBase , buffer_size : int = ...) -> None : ...
109
87
def seek (self , offset : int , whence : int = ...) -> int : ...
110
- def seekable (self ) -> bool : ...
111
88
def tell (self ) -> int : ...
112
- def truncate (self , size : int = ...) -> int : ...
113
- def writable (self ) -> bool : ...
114
- def write (self , s : str ) -> int : ...
115
- def writelines (self , lines : Iterable [str ]) -> None : ...
116
- def getvalue (self ) -> str : ...
117
89
118
- def __iter__ ( self ) -> Iterator [ str ]: ...
119
- def __enter__ (self ) -> 'StringIO' : ...
120
- def __exit__ ( self , t : type = None , value : BaseException = None , traceback : Any = None ) -> bool : ...
90
+ class BufferedRWPair ( BufferedIOBase ):
91
+ def __init__ (self , reader : RawIOBase , writer : RawIOBase ,
92
+ buffer_size : int = ... ) -> None : ...
121
93
122
- class TextIOWrapper (TextIO ):
123
- # TODO: This is actually a base class of _io._TextIOBase.
124
- # write_through is undocumented but used by subprocess
125
- def __init__ (self , buffer : IO [bytes ], encoding : str = ...,
126
- errors : str = ..., newline : str = ...,
127
- line_buffering : bool = ...,
128
- write_through : bool = ...) -> None : ...
129
- # TODO see comments in BinaryIO for missing functionality
130
- def close (self ) -> None : ...
131
- @property
132
- def closed (self ) -> bool : ...
133
- def fileno (self ) -> int : ...
134
- def flush (self ) -> None : ...
135
- def isatty (self ) -> bool : ...
136
- def read (self , n : int = ...) -> str : ...
137
- def readable (self ) -> bool : ...
138
- def readline (self , limit : int = ...) -> str : ...
139
- def readlines (self , hint : int = ...) -> List [str ]: ...
94
+
95
+ class TextIOBase (IOBase ):
96
+ encoding = ... # type: str
97
+ errors = ... # type: Optional[str]
98
+ def detach (self ) -> IOBase : ...
99
+ def read (self , size : Optional [int ] = ...) -> str : ...
100
+ @no_type_check # not same signature as parent
101
+ def readline (self , size : int = ...) -> str : ...
140
102
def seek (self , offset : int , whence : int = ...) -> int : ...
141
- def seekable (self ) -> bool : ...
142
103
def tell (self ) -> int : ...
143
- def truncate (self , size : int = ...) -> int : ...
144
- def writable (self ) -> bool : ...
145
104
def write (self , s : str ) -> int : ...
146
- def writelines (self , lines : Iterable [str ]) -> None : ...
147
105
148
- def __iter__ (self ) -> Iterator [str ]: ...
149
- def __enter__ (self ) -> StringIO : ...
150
- def __exit__ (self , t : type = None , value : BaseException = None , traceback : Any = None ) -> bool : ...
106
+ class TextIOWrapper (TextIOBase ):
107
+ line_buffering = ... # type: bool
108
+ def __init__ (self , buffer : BufferedIOBase , encoding : str = ...,
109
+ errors : str = ..., newline : Optional [str ] = ...,
110
+ line_buffering : bool = ...,
111
+ write_through : bool = ...) -> None : ...
112
+
113
+ class StringIO (TextIOBase ):
114
+ def __init__ (self , initial_value : str = ...,
115
+ newline : Optional [str ] = ...) -> None : ...
116
+ def getvalue (self ) -> str : ...
117
+
118
+ class IncrementalNewlineDecoder (codecs .IncrementalDecoder ): ...
0 commit comments