|
1 | 1 | # Stubs for io
|
2 | 2 |
|
3 | 3 | from typing import (
|
4 |
| - List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, no_type_check |
| 4 | + List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, Tuple |
5 | 5 | )
|
6 | 6 | import builtins
|
7 | 7 | import codecs
|
| 8 | +import sys |
8 | 9 | from types import TracebackType
|
9 | 10 |
|
10 | 11 | DEFAULT_BUFFER_SIZE = ... # type: int
|
11 |
| -SEEK_SET = ... # type: int |
12 |
| -SEEK_CUR = ... # type: int |
13 |
| -SEEK_END = ... # type: int |
14 | 12 |
|
15 |
| -open = builtins.open |
| 13 | +if sys.version_info >= (3, 1): |
| 14 | + SEEK_SET = ... # type: int |
| 15 | + SEEK_CUR = ... # type: int |
| 16 | + SEEK_END = ... # type: int |
16 | 17 |
|
17 |
| -class BlockingIOError(OSError): ... |
18 |
| -class UnsupportedOperation(ValueError, OSError): ... |
| 18 | +open = builtins.open |
19 | 19 |
|
| 20 | +if sys.version_info >= (3, 3): |
| 21 | + BlockingIOError = BlockingIOError |
| 22 | + class UnsupportedOperation(OSError, ValueError): ... |
| 23 | +else: |
| 24 | + class BlockingIOError(IOError): |
| 25 | + characters_written = ... # type: int |
| 26 | + class UnsupportedOperation(IOError, ValueError): ... |
20 | 27 |
|
21 | 28 | class IOBase:
|
22 |
| - @property |
| 29 | + def __iter__(self) -> Iterator[bytes]: ... |
| 30 | + def __next__(self) -> bytes: ... |
| 31 | + def __enter__(self) -> 'IOBase': ... |
| 32 | + def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], |
| 33 | + exc_tb: Optional[TracebackType]) -> bool: ... |
23 | 34 | def close(self) -> None: ...
|
24 |
| - def closed(self) -> bool: ... |
25 | 35 | def fileno(self) -> int: ...
|
26 | 36 | def flush(self) -> None: ...
|
27 | 37 | def isatty(self) -> bool: ...
|
28 | 38 | def readable(self) -> bool: ...
|
29 |
| - def readline(self, size: int = ...) -> bytes: ... |
30 |
| - def readlines(self, hint: int = ...) ->List[bytes]: ... |
| 39 | + def readlines(self, hint: int = ...) -> List[bytes]: ... |
31 | 40 | def seek(self, offset: int, whence: int = ...) -> int: ...
|
32 | 41 | def seekable(self) -> bool: ...
|
33 | 42 | def tell(self) -> int: ...
|
34 |
| - def truncate(self, size: int = ...) -> int: ... |
35 |
| - def writable(self) -> bool: ... |
36 |
| - def writelines(self, lines: bytes) -> None: ... |
37 |
| - def __del__(self) -> None: ... |
38 |
| - |
39 |
| - def __enter__(self) -> 'IOBase': ... |
40 |
| - def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception], |
41 |
| - exc_tb: Optional[TracebackType]) -> bool: ... |
42 |
| - def __iter__(self) -> Iterator[bytes]: ... |
43 |
| - def __next__(self) -> bytes: ... |
| 43 | + if sys.version_info >= (3, 4): |
| 44 | + def readline(self, size: int = ...) -> bytes: ... |
| 45 | + def __del__(self) -> None: ... |
| 46 | + else: |
| 47 | + def readline(self, limit: int = ...) -> bytes: ... # type: ignore |
| 48 | + if sys.version_info >= (3, 2): |
| 49 | + closed = ... # type: bool |
| 50 | + else: |
| 51 | + def closed(self) -> bool: ... # type: ignore |
| 52 | + if sys.version_info >= (3, 1): |
| 53 | + def truncate(self, size: Optional[int] = ...) -> int: ... |
| 54 | + else: |
| 55 | + def truncate(self, size: int = ...) -> int: ... |
| 56 | + if sys.version_info >= (3, 1): |
| 57 | + def writable(self) -> bool: ... |
| 58 | + def writelines(self, lines: bytes) -> None: ... |
44 | 59 |
|
45 | 60 | class RawIOBase(IOBase):
|
46 |
| - def read(self, size: int = ...) -> Optional[bytes]: ... |
47 | 61 | def readall(self) -> bytes: ...
|
48 |
| - def readinto(self, b: bytearray) -> Optional[int]: ... |
49 |
| - def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... |
| 62 | + if sys.version_info >= (3, 4): |
| 63 | + def read(self, size: int = ...) -> Optional[bytes]: ... |
| 64 | + else: |
| 65 | + def read(self, n: int = ...) -> Optional[bytes]: ... # type: ignore |
| 66 | + if sys.version_info >= (3, 1): |
| 67 | + def readinto(self, b: bytearray) -> Optional[int]: ... |
| 68 | + def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ... |
| 69 | + else: |
| 70 | + def readinto(self, b: bytearray) -> int: ... |
| 71 | + def write(self, b: Union[bytes, bytearray]) -> int: ... |
50 | 72 |
|
51 | 73 | class BufferedIOBase(IOBase):
|
52 |
| - def detach(self) -> 'RawIOBase': ... |
53 |
| - def read(self, size: Optional[int] = ...) -> bytes: ... |
54 |
| - def read1(self, size: int = ...) -> bytes: ... |
55 | 74 | def readinto(self, b: bytearray) -> int: ...
|
56 | 75 | def write(self, b: Union[bytes, bytearray]) -> int: ...
|
| 76 | + if sys.version_info >= (3, 5): |
| 77 | + def readinto1(self, b: bytearray) -> int: ... |
| 78 | + if sys.version_info >= (3, 4): |
| 79 | + def read(self, size: Optional[int] = ...) -> bytes: ... |
| 80 | + def read1(self, size: int = ...) -> bytes: ... |
| 81 | + elif sys.version_info >= (3, 1): |
| 82 | + def read(self, n: Optional[int] = ...) -> bytes: ... # type: ignore |
| 83 | + def read1(self, n: int = ...) -> bytes: ... # type: ignore |
| 84 | + if sys.version_info >= (3, 1): |
| 85 | + def detach(self) -> 'RawIOBase': ... |
57 | 86 |
|
58 | 87 |
|
59 | 88 | class FileIO(RawIOBase):
|
60 | 89 | mode = ... # type: str
|
61 | 90 | 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: ... |
| 91 | + if sys.version_info >= (3, 3): |
| 92 | + def __init__(self, name: Union[str, bytes, int], mode: str = ..., |
| 93 | + closefd: bool = ..., |
| 94 | + opener: Optional[ |
| 95 | + Callable[[Union[int, str], str], int]] = ...) \ |
| 96 | + -> None: ... |
| 97 | + elif sys.version_info >= (3, 1): |
| 98 | + def __init__(self, name: Union[str, bytes, int], # type: ignore |
| 99 | + mode: str = ..., closefd: bool = ...) -> None: ... |
| 100 | + else: |
| 101 | + def __init__(self, name: str, # type: ignore |
| 102 | + mode: str = ...) -> None: ... |
| 103 | + |
| 104 | + |
| 105 | +class BytesIO(BufferedIOBase): |
| 106 | + if sys.version_info >= (3, 1): |
| 107 | + def __init__(self, initial_bytes: bytes = ...) -> None: ... |
| 108 | + else: |
| 109 | + def __init__(self, # type: ignore |
| 110 | + initial_bytes: bytearray = ...) -> None: ... |
70 | 111 | def getvalue(self) -> bytes: ...
|
71 |
| - def read1(self, size: int = ...) -> Optional[bytes]: ... |
72 |
| - def readinto1(self, b: bytearray) -> int: ... |
| 112 | + if sys.version_info >= (3, 2): |
| 113 | + def getbuffer(self) -> memoryview: ... |
| 114 | + if sys.version_info < (3, 1): |
| 115 | + def read1(self) -> bytes: ... # type: ignore |
73 | 116 |
|
74 | 117 | class BufferedReader(BufferedIOBase):
|
75 | 118 | 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: ... |
| 119 | + if sys.version_info >= (3, 4): |
| 120 | + def peek(self, size: int = ...) -> bytes: ... |
| 121 | + else: |
| 122 | + def peek(self, n: int = ...) -> bytes: ... # type: ignore |
| 123 | + if sys.version_info < (3, 1): |
| 124 | + def read1(self, n: int = ...) -> bytes: ... |
79 | 125 |
|
80 | 126 | class BufferedWriter(BufferedIOBase):
|
81 |
| - def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... |
| 127 | + if sys.version_info >= (3, 1): |
| 128 | + def __init__(self, raw: RawIOBase, |
| 129 | + buffer_size: int = ...) -> None: ... |
| 130 | + else: |
| 131 | + def __init__(self, raw: RawIOBase, # type: ignore |
| 132 | + buffer_size: int = ..., max_buffer_size: int = ...) \ |
| 133 | + -> None: ... |
82 | 134 | def flush(self) -> None: ...
|
83 | 135 | def write(self, b: Union[bytes, bytearray]) -> int: ...
|
84 | 136 |
|
85 | 137 | class BufferedRandom(BufferedReader, BufferedWriter):
|
86 |
| - def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... |
87 |
| - def seek(self, offset: int, whence: int = ...) -> int: ... |
88 |
| - def tell(self) -> int: ... |
| 138 | + if sys.version_info >= (3, 1): |
| 139 | + def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... |
| 140 | + def seek(self, offset: int, whence: int = ...) -> int: ... |
| 141 | + def tell(self) -> int: ... |
| 142 | + else: |
| 143 | + def __init__(self, raw: RawIOBase, # type: ignore |
| 144 | + buffer_size: int = ..., max_buffer_size: int = ...) \ |
| 145 | + -> None: ... |
89 | 146 |
|
90 | 147 | class BufferedRWPair(BufferedIOBase):
|
91 |
| - def __init__(self, reader: RawIOBase, writer: RawIOBase, |
92 |
| - buffer_size: int = ...) -> None: ... |
| 148 | + if sys.version_info >= (3, 1): |
| 149 | + def __init__(self, reader: RawIOBase, writer: RawIOBase, |
| 150 | + buffer_size: int = ...) -> None: ... |
| 151 | + else: |
| 152 | + def __init__(self, reader: RawIOBase, writer: RawIOBase, # type: ignore |
| 153 | + buffer_size: int = ..., max_buffer_size: int = ...) \ |
| 154 | + -> None: ... |
93 | 155 |
|
94 | 156 |
|
95 | 157 | class TextIOBase(IOBase):
|
96 | 158 | 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: ... |
102 |
| - def seek(self, offset: int, whence: int = ...) -> int: ... |
103 |
| - def tell(self) -> int: ... |
| 159 | + newlines = ... # type: Union[str, Tuple[str, ...], None] |
| 160 | + def __iter__(self) -> Iterator[str]: ... # type: ignore |
| 161 | + def __next__(self) -> str: ... # type: ignore |
| 162 | + def __enter__(self) -> 'TextIOBase': ... |
104 | 163 | def write(self, s: str) -> int: ...
|
| 164 | + if sys.version_info >= (3, 4): |
| 165 | + def readline(self, size: int = ...) -> str: ... # type: ignore |
| 166 | + def read(self, size: Optional[int] = ...) -> str: ... |
| 167 | + elif sys.version_info >= (3, 2): |
| 168 | + def readline(self, limit: int = ...) -> str: ... # type: ignore |
| 169 | + else: |
| 170 | + def readline(self) -> str: ... # type: ignore |
| 171 | + if sys.version_info >= (3, 2): |
| 172 | + def seek(self, offset: int, whence: int = ...) -> int: ... |
| 173 | + def tell(self) -> int: ... |
| 174 | + if sys.version_info >= (3, 1): |
| 175 | + errors = ... # type: Optional[str] |
| 176 | + def detach(self) -> IOBase: ... |
| 177 | + else: |
| 178 | + def read(self, n: Optional[int] = ...) -> str: ... # type: ignore |
105 | 179 |
|
106 | 180 | class TextIOWrapper(TextIOBase):
|
107 | 181 | 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: ... |
| 182 | + if sys.version_info >= (3, 3): |
| 183 | + def __init__(self, buffer: BufferedIOBase, encoding: str = ..., |
| 184 | + errors: Optional[str] = ..., newline: Optional[str] = ..., |
| 185 | + line_buffering: bool = ..., write_through: bool = ...) \ |
| 186 | + -> None: ... |
| 187 | + else: |
| 188 | + def __init__(self, buffer: BufferedIOBase, # type: ignore |
| 189 | + encoding: str = ..., errors: Optional[str] = ..., |
| 190 | + newline: Optional[str] = ..., line_buffering: bool = ...) \ |
| 191 | + -> None: ... |
| 192 | + if sys.version_info < (3, 1): |
| 193 | + errors = ... # type: Optional[str] |
| 194 | + |
| 195 | +class StringIO(TextIOWrapper): |
| 196 | + if sys.version_info >= (3, 1): |
| 197 | + def __init__(self, initial_value: str = ..., |
| 198 | + newline: Optional[str] = ...) -> None: ... |
| 199 | + else: |
| 200 | + def __init__(self, initial_value: str = ..., # type: ignore |
| 201 | + encoding: str = ..., errors: Optional[str] = ..., |
| 202 | + newline: Optional[str] = ...) -> None: ... |
116 | 203 | def getvalue(self) -> str: ...
|
117 | 204 |
|
118 | 205 | class IncrementalNewlineDecoder(codecs.IncrementalDecoder): ...
|
0 commit comments