Skip to content

Commit bb0a841

Browse files
authored
Make io._IOBase and its descendents concrete. (#1172)
This solves the issue with instantiating gzip.GzipFile() mentioned at #1160 (comment)
1 parent 70f7f6c commit bb0a841

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

stdlib/2/_io.pyi

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, BinaryIO, Optional, Iterable, Tuple, List, Union
1+
from typing import Any, BinaryIO, IO, Iterable, Iterator, List, Optional, Type, Tuple, Union
22

33
DEFAULT_BUFFER_SIZE = ... # type: int
44

@@ -14,6 +14,28 @@ class _IOBase(BinaryIO):
1414
def _checkReadable(self) -> None: ...
1515
def _checkSeekable(self) -> None: ...
1616
def _checkWritable(self) -> None: ...
17+
# All these methods are concrete here (you can instantiate this)
18+
def close(self) -> None: ...
19+
def fileno(self) -> int: ...
20+
def flush(self) -> None: ...
21+
def isatty(self) -> bool: ...
22+
def read(self, n: int = ...) -> bytes: ...
23+
def readable(self) -> bool: ...
24+
def readline(self, limit: int = ...) -> bytes: ...
25+
def readlines(self, hint: int = ...) -> list[bytes]: ...
26+
def seek(self, offset: int, whence: int = ...) -> int: ...
27+
def seekable(self) -> bool: ...
28+
def tell(self) -> int: ...
29+
def truncate(self, size: Optional[int] = ...) -> int: ...
30+
def writable(self) -> bool: ...
31+
def write(self, s: bytes) -> int: ...
32+
def writelines(self, lines: Iterable[bytes]) -> None: ...
33+
def next(self) -> bytes: ...
34+
def __iter__(self) -> Iterator[bytes]: ...
35+
def __enter__(self) -> '_IOBase': ...
36+
def __exit__(self, t: Optional[Type[BaseException]], value: Optional[BaseException],
37+
# TODO: traceback should be TracebackType but that's defined in types
38+
traceback: Optional[Any]) -> bool: ...
1739

1840
class _BufferedIOBase(_IOBase):
1941
def read1(self, n: int) -> str: ...

stdlib/2/io.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,4 @@ class TextIOWrapper(TextIO):
101101
def __enter__(self) -> StringIO: ...
102102
def __exit__(self, type, value, traceback) -> bool: ...
103103

104-
class BufferedIOBase(IOBase): ...
104+
class BufferedIOBase(_io._BufferedIOBase, IOBase): ...

0 commit comments

Comments
 (0)