Skip to content

Commit a7f9e30

Browse files
committed
improve io
1 parent 33fe6a0 commit a7f9e30

File tree

3 files changed

+82
-161
lines changed

3 files changed

+82
-161
lines changed

stdlib/3.5/xml/etree/ElementTree.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# NOTE: This dynamically typed stub was automatically generated by stubgen.
44

5-
from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator
5+
from typing import Any, AnyStr, Union, IO, Callable, Dict, List, Tuple, Sequence, Iterator, TypeVar, Optional, KeysView, ItemsView, Generator, no_type_check
66
import io
77

88
VERSION = ... # type: str
@@ -80,6 +80,7 @@ class _ListDataStream(io.BufferedIOBase):
8080
def __init__(self, lst) -> None: ...
8181
def writable(self) -> bool: ...
8282
def seekable(self) -> bool: ...
83+
@no_type_check # no the same signature as parent
8384
def write(self, b: str) -> None: ...
8485
def tell(self) -> int: ...
8586

stdlib/3/_io.pyi

Lines changed: 0 additions & 48 deletions
This file was deleted.

stdlib/3/io.pyi

Lines changed: 80 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Stubs for io
22

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+
)
66
import builtins
77
import codecs
8-
import _io
8+
from types import TracebackType
99

10-
DEFAULT_BUFFER_SIZE = 0 # type: int
10+
DEFAULT_BUFFER_SIZE = ... # type: int
1111
SEEK_SET = ... # type: int
1212
SEEK_CUR = ... # type: int
1313
SEEK_END = ... # type: int
@@ -17,134 +17,102 @@ open = builtins.open
1717
class BlockingIOError(OSError): ...
1818
class UnsupportedOperation(ValueError, OSError): ...
1919

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 = ...): ...
6320

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:
6922
@property
23+
def close(self) -> None: ...
7024
def closed(self) -> bool: ...
7125
def fileno(self) -> int: ...
7226
def flush(self) -> None: ...
7327
def isatty(self) -> bool: ...
74-
def read(self, n: int = ...) -> bytes: ...
7528
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]: ...
7831
def seek(self, offset: int, whence: int = ...) -> int: ...
7932
def seekable(self) -> bool: ...
8033
def tell(self) -> int: ...
8134
def truncate(self, size: int = ...) -> int: ...
8235
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: ...
9038

39+
def __enter__(self) -> 'IOBase': ...
40+
def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception],
41+
exc_tb: Optional[TracebackType]) -> bool: ...
9142
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: ...
9444

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: ...
10382
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: ...
10987
def seek(self, offset: int, whence: int = ...) -> int: ...
110-
def seekable(self) -> bool: ...
11188
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: ...
11789

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: ...
12193

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: ...
140102
def seek(self, offset: int, whence: int = ...) -> int: ...
141-
def seekable(self) -> bool: ...
142103
def tell(self) -> int: ...
143-
def truncate(self, size: int = ...) -> int: ...
144-
def writable(self) -> bool: ...
145104
def write(self, s: str) -> int: ...
146-
def writelines(self, lines: Iterable[str]) -> None: ...
147105

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

Comments
 (0)