Skip to content

Commit a779e0a

Browse files
committed
add version specific io
1 parent ad4b15e commit a779e0a

File tree

1 file changed

+148
-61
lines changed

1 file changed

+148
-61
lines changed

stdlib/3/io.pyi

Lines changed: 148 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,205 @@
11
# Stubs for io
22

33
from typing import (
4-
List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, no_type_check
4+
List, BinaryIO, TextIO, Iterator, Union, Optional, Callable, Tuple
55
)
66
import builtins
77
import codecs
8+
import sys
89
from types import TracebackType
910

1011
DEFAULT_BUFFER_SIZE = ... # type: int
11-
SEEK_SET = ... # type: int
12-
SEEK_CUR = ... # type: int
13-
SEEK_END = ... # type: int
1412

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
1617

17-
class BlockingIOError(OSError): ...
18-
class UnsupportedOperation(ValueError, OSError): ...
18+
open = builtins.open
1919

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): ...
2027

2128
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: ...
2334
def close(self) -> None: ...
24-
def closed(self) -> bool: ...
2535
def fileno(self) -> int: ...
2636
def flush(self) -> None: ...
2737
def isatty(self) -> bool: ...
2838
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]: ...
3140
def seek(self, offset: int, whence: int = ...) -> int: ...
3241
def seekable(self) -> bool: ...
3342
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: ...
4459

4560
class RawIOBase(IOBase):
46-
def read(self, size: int = ...) -> Optional[bytes]: ...
4761
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: ...
5072

5173
class BufferedIOBase(IOBase):
52-
def detach(self) -> 'RawIOBase': ...
53-
def read(self, size: Optional[int] = ...) -> bytes: ...
54-
def read1(self, size: int = ...) -> bytes: ...
5574
def readinto(self, b: bytearray) -> int: ...
5675
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': ...
5786

5887

5988
class FileIO(RawIOBase):
6089
mode = ... # type: str
6190
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: ...
70111
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
73116

74117
class BufferedReader(BufferedIOBase):
75118
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: ...
79125

80126
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: ...
82134
def flush(self) -> None: ...
83135
def write(self, b: Union[bytes, bytearray]) -> int: ...
84136

85137
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: ...
89146

90147
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: ...
93155

94156

95157
class TextIOBase(IOBase):
96158
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': ...
104163
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
105179

106180
class TextIOWrapper(TextIOBase):
107181
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: ...
116203
def getvalue(self) -> str: ...
117204

118205
class IncrementalNewlineDecoder(codecs.IncrementalDecoder): ...

0 commit comments

Comments
 (0)