Skip to content

Commit fe1a623

Browse files
committed
add version specific io
1 parent 36e2be4 commit fe1a623

File tree

1 file changed

+149
-61
lines changed

1 file changed

+149
-61
lines changed

stdlib/3/io.pyi

Lines changed: 149 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,206 @@
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, no_type_check,
5+
Tuple
56
)
67
import builtins
78
import codecs
9+
import sys
810
from types import TracebackType
911

1012
DEFAULT_BUFFER_SIZE = ... # type: int
11-
SEEK_SET = ... # type: int
12-
SEEK_CUR = ... # type: int
13-
SEEK_END = ... # type: int
1413

15-
open = builtins.open
14+
if sys.version_info >= (3, 1):
15+
SEEK_SET = ... # type: int
16+
SEEK_CUR = ... # type: int
17+
SEEK_END = ... # type: int
1618

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

21+
if sys.version_info >= (3, 3):
22+
BlockingIOError = BlockingIOError
23+
class UnsupportedOperation(OSError, ValueError): ...
24+
else:
25+
class BlockingIOError(IOError):
26+
characters_written = ... # type: int
27+
class UnsupportedOperation(IOError, ValueError): ...
2028

2129
class IOBase:
22-
@property
30+
def __iter__(self) -> Iterator[bytes]: ...
31+
def __next__(self) -> bytes: ...
32+
def __enter__(self) -> 'IOBase': ...
33+
def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception],
34+
exc_tb: Optional[TracebackType]) -> bool: ...
2335
def close(self) -> None: ...
24-
def closed(self) -> bool: ...
2536
def fileno(self) -> int: ...
2637
def flush(self) -> None: ...
2738
def isatty(self) -> bool: ...
2839
def readable(self) -> bool: ...
29-
def readline(self, size: int = ...) -> bytes: ...
30-
def readlines(self, hint: int = ...) ->List[bytes]: ...
40+
def readlines(self, hint: int = ...) -> List[bytes]: ...
3141
def seek(self, offset: int, whence: int = ...) -> int: ...
3242
def seekable(self) -> bool: ...
3343
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: ...
44+
if sys.version_info >= (3, 4):
45+
def readline(self, size: int = ...) -> bytes: ...
46+
def __del__(self) -> None: ...
47+
else:
48+
def readline(self, limit: int = ...) -> bytes: ... # type: ignore
49+
if sys.version_info >= (3, 2):
50+
closed = ... # type: bool
51+
else:
52+
def closed(self) -> bool: ... # type: ignore
53+
if sys.version_info >= (3, 1):
54+
def truncate(self, size: Optional[int] = ...) -> int: ...
55+
else:
56+
def truncate(self, size: int = ...) -> int: ...
57+
if sys.version_info >= (3, 1):
58+
def writable(self) -> bool: ...
59+
def writelines(self, lines: bytes) -> None: ...
4460

4561
class RawIOBase(IOBase):
46-
def read(self, size: int = ...) -> Optional[bytes]: ...
4762
def readall(self) -> bytes: ...
48-
def readinto(self, b: bytearray) -> Optional[int]: ...
49-
def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ...
63+
if sys.version_info >= (3, 4):
64+
def read(self, size: int = ...) -> Optional[bytes]: ...
65+
else:
66+
def read(self, n: int = ...) -> Optional[bytes]: ... # type: ignore
67+
if sys.version_info >= (3, 1):
68+
def readinto(self, b: bytearray) -> Optional[int]: ...
69+
def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ...
70+
else:
71+
def readinto(self, b: bytearray) -> int: ...
72+
def write(self, b: Union[bytes, bytearray]) -> int: ...
5073

5174
class BufferedIOBase(IOBase):
52-
def detach(self) -> 'RawIOBase': ...
53-
def read(self, size: Optional[int] = ...) -> bytes: ...
54-
def read1(self, size: int = ...) -> bytes: ...
5575
def readinto(self, b: bytearray) -> int: ...
5676
def write(self, b: Union[bytes, bytearray]) -> int: ...
77+
if sys.version_info >= (3, 5):
78+
def readinto1(self, b: bytearray) -> int: ...
79+
if sys.version_info >= (3, 4):
80+
def read(self, size: Optional[int] = ...) -> bytes: ...
81+
def read1(self, size: int = ...) -> bytes: ...
82+
elif sys.version_info >= (3, 1):
83+
def read(self, n: Optional[int] = ...) -> bytes: ... # type: ignore
84+
def read1(self, n: int = ...) -> bytes: ... # type: ignore
85+
if sys.version_info >= (3, 1):
86+
def detach(self) -> 'RawIOBase': ...
5787

5888

5989
class FileIO(RawIOBase):
6090
mode = ... # type: str
6191
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: ...
92+
if sys.version_info >= (3, 3):
93+
def __init__(self, name: Union[str, bytes, int], mode: str = ...,
94+
closefd: bool = ...,
95+
opener: Optional[
96+
Callable[[Union[int, str], str], int]] = ...) \
97+
-> None: ...
98+
elif sys.version_info >= (3, 1):
99+
def __init__(self, name: Union[str, bytes, int], # type: ignore
100+
mode: str = ..., closefd: bool = ...) -> None: ...
101+
else:
102+
def __init__(self, name: str, # type: ignore
103+
mode: str = ...) -> None: ...
104+
105+
106+
class BytesIO(BufferedIOBase):
107+
if sys.version_info >= (3, 1):
108+
def __init__(self, initial_bytes: bytes = ...) -> None: ...
109+
else:
110+
def __init__(self, # type: ignore
111+
initial_bytes: bytearray = ...) -> None: ...
70112
def getvalue(self) -> bytes: ...
71-
def read1(self, size: int = ...) -> Optional[bytes]: ...
72-
def readinto1(self, b: bytearray) -> int: ...
113+
if sys.version_info >= (3, 2):
114+
def getbuffer(self) -> memoryview: ...
115+
if sys.version_info < (3, 1):
116+
def read1(self) -> bytes: ... # type: ignore
73117

74118
class BufferedReader(BufferedIOBase):
75119
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: ...
120+
if sys.version_info >= (3, 4):
121+
def peek(self, size: int = ...) -> bytes: ...
122+
else:
123+
def peek(self, n: int = ...) -> bytes: ... # type: ignore
124+
if sys.version_info < (3, 1):
125+
def read1(self, n: int = ...) -> bytes: ...
79126

80127
class BufferedWriter(BufferedIOBase):
81-
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
128+
if sys.version_info >= (3, 1):
129+
def __init__(self, raw: RawIOBase,
130+
buffer_size: int = ...) -> None: ...
131+
else:
132+
def __init__(self, raw: RawIOBase, # type: ignore
133+
buffer_size: int = ..., max_buffer_size: int = ...) \
134+
-> None: ...
82135
def flush(self) -> None: ...
83136
def write(self, b: Union[bytes, bytearray]) -> int: ...
84137

85138
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: ...
139+
if sys.version_info >= (3, 1):
140+
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
141+
def seek(self, offset: int, whence: int = ...) -> int: ...
142+
def tell(self) -> int: ...
143+
else:
144+
def __init__(self, raw: RawIOBase, # type: ignore
145+
buffer_size: int = ..., max_buffer_size: int = ...) \
146+
-> None: ...
89147

90148
class BufferedRWPair(BufferedIOBase):
91-
def __init__(self, reader: RawIOBase, writer: RawIOBase,
92-
buffer_size: int = ...) -> None: ...
149+
if sys.version_info >= (3, 1):
150+
def __init__(self, reader: RawIOBase, writer: RawIOBase,
151+
buffer_size: int = ...) -> None: ...
152+
else:
153+
def __init__(self, reader: RawIOBase, writer: RawIOBase, # type: ignore
154+
buffer_size: int = ..., max_buffer_size: int = ...) \
155+
-> None: ...
93156

94157

95158
class TextIOBase(IOBase):
96159
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: ...
160+
newlines = ... # type: Union[str, Tuple[str, ...], None]
161+
def __iter__(self) -> Iterator[str]: ... # type: ignore
162+
def __next__(self) -> str: ... # type: ignore
163+
def __enter__(self) -> 'TextIOBase': ...
104164
def write(self, s: str) -> int: ...
165+
if sys.version_info >= (3, 4):
166+
def readline(self, size: int = ...) -> str: ... # type: ignore
167+
def read(self, size: Optional[int] = ...) -> str: ...
168+
elif sys.version_info >= (3, 2):
169+
def readline(self, limit: int = ...) -> str: ... # type: ignore
170+
else:
171+
def readline(self) -> str: ... # type: ignore
172+
if sys.version_info >= (3, 2):
173+
def seek(self, offset: int, whence: int = ...) -> int: ...
174+
def tell(self) -> int: ...
175+
if sys.version_info >= (3, 1):
176+
errors = ... # type: Optional[str]
177+
def detach(self) -> IOBase: ...
178+
else:
179+
def read(self, n: Optional[int] = ...) -> str: ... # type: ignore
105180

106181
class TextIOWrapper(TextIOBase):
107182
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: ...
183+
if sys.version_info >= (3, 3):
184+
def __init__(self, buffer: BufferedIOBase, encoding: str = ...,
185+
errors: Optional[str] = ..., newline: Optional[str] = ...,
186+
line_buffering: bool = ..., write_through: bool = ...) \
187+
-> None: ...
188+
else:
189+
def __init__(self, buffer: BufferedIOBase, # type: ignore
190+
encoding: str = ..., errors: Optional[str] = ...,
191+
newline: Optional[str] = ..., line_buffering: bool = ...) \
192+
-> None: ...
193+
if sys.version_info < (3, 1):
194+
errors = ... # type: Optional[str]
195+
196+
class StringIO(TextIOWrapper):
197+
if sys.version_info >= (3, 1):
198+
def __init__(self, initial_value: str = ...,
199+
newline: Optional[str] = ...) -> None: ...
200+
else:
201+
def __init__(self, initial_value: str = ..., # type: ignore
202+
encoding: str = ..., errors: Optional[str] = ...,
203+
newline: Optional[str] = ...) -> None: ...
116204
def getvalue(self) -> str: ...
117205

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

0 commit comments

Comments
 (0)