Skip to content

Commit 0b342d0

Browse files
committed
improve io
1 parent 33fe6a0 commit 0b342d0

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,14 @@
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, IO, overload, Iterator, Iterable, Any, Union, Tuple,
5+
Optional, Callable
6+
)
67
import builtins
78
import codecs
8-
import _io
9+
from types import TracebackType
910

10-
DEFAULT_BUFFER_SIZE = 0 # type: int
11+
DEFAULT_BUFFER_SIZE = ... # type: int
1112
SEEK_SET = ... # type: int
1213
SEEK_CUR = ... # type: int
1314
SEEK_END = ... # type: int
@@ -17,134 +18,101 @@ open = builtins.open
1718
class BlockingIOError(OSError): ...
1819
class UnsupportedOperation(ValueError, OSError): ...
1920

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

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: ...
22+
class IOBase:
6923
@property
24+
def close(self) -> None: ...
7025
def closed(self) -> bool: ...
7126
def fileno(self) -> int: ...
7227
def flush(self) -> None: ...
7328
def isatty(self) -> bool: ...
74-
def read(self, n: int = ...) -> bytes: ...
7529
def readable(self) -> bool: ...
76-
def readline(self, limit: int = ...) -> bytes: ...
77-
def readlines(self, hint: int = ...) -> List[bytes]: ...
30+
def readline(self, size: int = ...) -> bytes: ...
31+
def readlines(self, hint: int = ...) ->List[bytes]: ...
7832
def seek(self, offset: int, whence: int = ...) -> int: ...
7933
def seekable(self) -> bool: ...
8034
def tell(self) -> int: ...
8135
def truncate(self, size: int = ...) -> int: ...
8236
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: ...
37+
def writelines(self, lines: bytes) -> None: ...
38+
def __del__(self) -> None: ...
9039

40+
def __enter__(self) -> 'IOBase': ...
41+
def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception],
42+
exc_tb: Optional[TracebackType]) -> bool: ...
9143
def __iter__(self) -> Iterator[bytes]: ...
92-
def __enter__(self) -> 'BytesIO': ...
93-
def __exit__(self, t: type = None, value: BaseException = None, traceback: Any = None) -> bool: ...
44+
def __next__(self) -> bytes: ...
9445

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: ...
46+
class RawIOBase(IOBase):
47+
def read(self, size: int = ...) -> Optional[bytes]: ...
48+
def readall(self) -> bytes: ...
49+
def readinto(self, b: bytearray) -> Optional[int]: ...
50+
def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ...
51+
52+
class BufferedIOBase(IOBase):
53+
def detach(self) -> 'RawIOBase': ...
54+
def read(self, size: Optional[int] = ...) -> bytes: ...
55+
def read1(self, size: int = ...) -> bytes: ...
56+
def readinto(self, b: bytearray) -> int: ...
57+
def write(self, b: Union[bytes, bytearray]) -> int: ...
58+
59+
60+
class FileIO(RawIOBase):
61+
mode = ... # type: str
62+
name = ... # type: Union[int, str]
63+
def __init__(self, name: Union[int, str], mode: str = ...,
64+
closefd: bool = ...,
65+
opener: Optional[Callable[[Union[int, str], int], Union[TextIO, BytesIO]]] = ...) -> None: ...
66+
67+
68+
class BytesIO(BinaryIO):
69+
def __init__(self, initial_bytes: bytes = ...) -> None: ...
70+
def getbuffer(self) -> memoryview: ...
71+
def getvalue(self) -> bytes: ...
72+
def read1(self, size: int = ...) -> Optional[bytes]: ...
73+
def readinto1(self, b: bytearray) -> int: ...
74+
75+
class BufferedReader(BufferedIOBase):
76+
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
77+
def peek(self, size: int = ...) -> bytes: ...
78+
def read(self, size: int = ...) -> bytes: ...
79+
def read1(self, size: int = ...) -> bytes: ...
80+
81+
class BufferedWriter(BufferedIOBase):
82+
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
10383
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]: ...
84+
def write(self, b: Union[bytes, bytearray]) -> int: ...
85+
86+
class BufferedRandom(BufferedReader, BufferedWriter):
87+
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
10988
def seek(self, offset: int, whence: int = ...) -> int: ...
110-
def seekable(self) -> bool: ...
11189
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: ...
11790

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: ...
91+
class BufferedRWPair(BufferedIOBase):
92+
def __init__(self, reader: RawIOBase, writer: RawIOBase,
93+
buffer_size: int = ...) -> None: ...
12194

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]: ...
95+
96+
class TextIOBase(IOBase):
97+
encoding = ... # type: str
98+
errors = ... # type: Optional[str]
99+
def detach(self) -> IOBase: ...
100+
def read(self, size: Optional[int] = ...) -> str: ...
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)