Skip to content

Commit 9fdac6e

Browse files
tharvikgvanrossum
authored andcommitted
improve io (#194)
* added types to io, some version-specific variants * remove _io (moved the classes to io) * remove internal, unused xml.etree._ListDataStream
1 parent 33fe6a0 commit 9fdac6e

File tree

5 files changed

+136
-197
lines changed

5 files changed

+136
-197
lines changed

stdlib/3.3/xml/etree/ElementTree.pyi

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ class ElementTree:
7474

7575
def register_namespace(prefix: str, uri: str) -> None: ...
7676
def tostring(element: Element, encoding: str=..., method: str=...) -> str: ...
77-
78-
class _ListDataStream(io.BufferedIOBase):
79-
lst = ... # type: List[str]
80-
def __init__(self, lst) -> None: ...
81-
def writable(self) -> bool: ...
82-
def seekable(self) -> bool: ...
83-
def write(self, b: str) -> None: ...
84-
def tell(self) -> int: ...
85-
8677
def tostringlist(element: Element, encoding: str=..., method: str=...) -> List[str]: ...
8778
def dump(elem: Element) -> None: ...
8879
def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ...

stdlib/3.4/xml/etree/ElementTree.pyi

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ class ElementTree:
7474

7575
def register_namespace(prefix: str, uri: str) -> None: ...
7676
def tostring(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> str: ...
77-
78-
class _ListDataStream(io.BufferedIOBase):
79-
lst = ... # type: List[str]
80-
def __init__(self, lst) -> None: ...
81-
def writable(self) -> bool: ...
82-
def seekable(self) -> bool: ...
83-
def write(self, b: str) -> None: ...
84-
def tell(self) -> int: ...
85-
8677
def tostringlist(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> List[str]: ...
8778
def dump(elem: Element) -> None: ...
8879
def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ...

stdlib/3.5/xml/etree/ElementTree.pyi

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ class ElementTree:
7474

7575
def register_namespace(prefix: str, uri: str) -> None: ...
7676
def tostring(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> str: ...
77-
78-
class _ListDataStream(io.BufferedIOBase):
79-
lst = ... # type: List[str]
80-
def __init__(self, lst) -> None: ...
81-
def writable(self) -> bool: ...
82-
def seekable(self) -> bool: ...
83-
def write(self, b: str) -> None: ...
84-
def tell(self) -> int: ...
85-
8677
def tostringlist(element: Element, encoding: str=..., method: str=..., *, short_empty_elements: bool=...) -> List[str]: ...
8778
def dump(elem: Element) -> None: ...
8879
def parse(source: _file_or_filename, parser: 'XMLParser'=...) -> ElementTree: ...

stdlib/3/_io.pyi

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

stdlib/3/io.pyi

Lines changed: 136 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,164 @@
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, Tuple
5+
)
66
import builtins
77
import codecs
8-
import _io
8+
import sys
9+
from types import TracebackType
10+
11+
DEFAULT_BUFFER_SIZE = ... # type: int
912

10-
DEFAULT_BUFFER_SIZE = 0 # type: int
1113
SEEK_SET = ... # type: int
1214
SEEK_CUR = ... # type: int
1315
SEEK_END = ... # type: int
1416

1517
open = builtins.open
1618

17-
class BlockingIOError(OSError): ...
18-
class UnsupportedOperation(ValueError, OSError): ...
19-
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 = ...): ...
63-
64-
class BytesIO(BinaryIO):
65-
def __init__(self, initial_bytes: bytes = ...) -> None: ...
66-
# TODO getbuffer
67-
# TODO see comments in BinaryIO for missing functionality
19+
# FIXME when mypy handle condtional, we can uncomment the next block and remove
20+
# the temporary fix
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): ...
28+
class BlockingIOError(OSError):
29+
characters_written = ... # type: int
30+
class UnsupportedOperation(OSError, ValueError): ...
31+
32+
33+
class IOBase:
34+
def __iter__(self) -> Iterator[bytes]: ...
35+
def __next__(self) -> bytes: ...
36+
def __enter__(self) -> 'IOBase': ...
37+
def __exit__(self, exc_type: Optional[type], exc_val: Optional[Exception],
38+
exc_tb: Optional[TracebackType]) -> bool: ...
6839
def close(self) -> None: ...
69-
@property
70-
def closed(self) -> bool: ...
7140
def fileno(self) -> int: ...
7241
def flush(self) -> None: ...
7342
def isatty(self) -> bool: ...
74-
def read(self, n: int = ...) -> bytes: ...
7543
def readable(self) -> bool: ...
76-
def readline(self, limit: int = ...) -> bytes: ...
7744
def readlines(self, hint: int = ...) -> List[bytes]: ...
7845
def seek(self, offset: int, whence: int = ...) -> int: ...
7946
def seekable(self) -> bool: ...
8047
def tell(self) -> int: ...
81-
def truncate(self, size: int = ...) -> int: ...
48+
def truncate(self, size: Optional[int] = ...) -> int: ...
8249
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: ...
50+
def writelines(self, lines: bytes) -> None: ...
51+
if sys.version_info >= (3, 4):
52+
def readline(self, size: int = ...) -> bytes: ...
53+
def __del__(self) -> None: ...
54+
else:
55+
def readline(self, limit: int = ...) -> bytes: ... # type: ignore
56+
if sys.version_info >= (3, 2):
57+
closed = ... # type: bool
58+
else:
59+
def closed(self) -> bool: ... # type: ignore
60+
61+
class RawIOBase(IOBase):
62+
def readall(self) -> bytes: ...
63+
def readinto(self, b: bytearray) -> Optional[int]: ...
64+
def write(self, b: Union[bytes, bytearray]) -> Optional[int]: ...
65+
if sys.version_info >= (3, 4):
66+
def read(self, size: int = ...) -> Optional[bytes]: ...
67+
else:
68+
def read(self, n: int = ...) -> Optional[bytes]: ... # type: ignore
69+
70+
class BufferedIOBase(IOBase):
71+
def detach(self) -> 'RawIOBase': ...
72+
def readinto(self, b: bytearray) -> int: ...
73+
def write(self, b: Union[bytes, bytearray]) -> int: ...
74+
if sys.version_info >= (3, 5):
75+
def readinto1(self, b: bytearray) -> int: ...
76+
if sys.version_info >= (3, 4):
77+
def read(self, size: Optional[int] = ...) -> bytes: ...
78+
def read1(self, size: int = ...) -> bytes: ...
79+
else:
80+
def read(self, n: Optional[int] = ...) -> bytes: ... # type: ignore
81+
def read1(self, n: int = ...) -> bytes: ... # type: ignore
82+
83+
84+
class FileIO(RawIOBase):
85+
mode = ... # type: str
86+
name = ... # type: Union[int, str]
87+
if sys.version_info >= (3, 3):
88+
def __init__(self, name: Union[str, bytes, int], mode: str = ...,
89+
closefd: bool = ...,
90+
opener: Optional[
91+
Callable[[Union[int, str], str], int]] = ...) \
92+
-> None: ...
93+
else:
94+
def __init__(self, name: Union[str, bytes, int], # type: ignore
95+
mode: str = ..., closefd: bool = ...) -> None: ...
96+
97+
98+
class BytesIO(BufferedIOBase):
99+
def __init__(self, initial_bytes: bytes = ...) -> None: ...
88100
def getvalue(self) -> bytes: ...
89-
def read1(self) -> str: ...
90-
91-
def __iter__(self) -> Iterator[bytes]: ...
92-
def __enter__(self) -> 'BytesIO': ...
93-
def __exit__(self, t: type = None, value: BaseException = None, traceback: Any = None) -> bool: ...
94-
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: ...
101+
if sys.version_info >= (3, 2):
102+
def getbuffer(self) -> memoryview: ...
103+
104+
class BufferedReader(BufferedIOBase):
105+
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
106+
if sys.version_info >= (3, 4):
107+
def peek(self, size: int = ...) -> bytes: ...
108+
else:
109+
def peek(self, n: int = ...) -> bytes: ... # type: ignore
110+
111+
class BufferedWriter(BufferedIOBase):
112+
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
103113
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]: ...
109-
def seek(self, offset: int, whence: int = ...) -> int: ...
110-
def seekable(self) -> bool: ...
111-
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: ...
114+
def write(self, b: Union[bytes, bytearray]) -> int: ...
117115

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: ...
121-
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]: ...
116+
class BufferedRandom(BufferedReader, BufferedWriter):
117+
def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ...
140118
def seek(self, offset: int, whence: int = ...) -> int: ...
141-
def seekable(self) -> bool: ...
142119
def tell(self) -> int: ...
143-
def truncate(self, size: int = ...) -> int: ...
144-
def writable(self) -> bool: ...
120+
121+
class BufferedRWPair(BufferedIOBase):
122+
def __init__(self, reader: RawIOBase, writer: RawIOBase,
123+
buffer_size: int = ...) -> None: ...
124+
125+
126+
class TextIOBase(IOBase):
127+
encoding = ... # type: str
128+
errors = ... # type: Optional[str]
129+
newlines = ... # type: Union[str, Tuple[str, ...], None]
130+
def __iter__(self) -> Iterator[str]: ... # type: ignore
131+
def __next__(self) -> str: ... # type: ignore
132+
def __enter__(self) -> 'TextIOBase': ...
133+
def detach(self) -> IOBase: ...
145134
def write(self, s: str) -> int: ...
146-
def writelines(self, lines: Iterable[str]) -> None: ...
135+
if sys.version_info >= (3, 4):
136+
def readline(self, size: int = ...) -> str: ... # type: ignore
137+
def read(self, size: Optional[int] = ...) -> str: ...
138+
elif sys.version_info >= (3, 2):
139+
def readline(self, limit: int = ...) -> str: ... # type: ignore
140+
else:
141+
def readline(self) -> str: ... # type: ignore
142+
if sys.version_info >= (3, 2):
143+
def seek(self, offset: int, whence: int = ...) -> int: ...
144+
def tell(self) -> int: ...
145+
146+
class TextIOWrapper(TextIOBase):
147+
line_buffering = ... # type: bool
148+
if sys.version_info >= (3, 3):
149+
def __init__(self, buffer: BufferedIOBase, encoding: str = ...,
150+
errors: Optional[str] = ..., newline: Optional[str] = ...,
151+
line_buffering: bool = ..., write_through: bool = ...) \
152+
-> None: ...
153+
else:
154+
def __init__(self, buffer: BufferedIOBase, # type: ignore
155+
encoding: str = ..., errors: Optional[str] = ...,
156+
newline: Optional[str] = ..., line_buffering: bool = ...) \
157+
-> None: ...
158+
159+
class StringIO(TextIOWrapper):
160+
def __init__(self, initial_value: str = ...,
161+
newline: Optional[str] = ...) -> None: ...
162+
def getvalue(self) -> str: ...
147163

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: ...
164+
class IncrementalNewlineDecoder(codecs.IncrementalDecoder): ...

0 commit comments

Comments
 (0)