Skip to content

Commit dac770d

Browse files
authored
[_io] Turn _IOBase.read() and write() into functions (#16583)
1 parent a5329cb commit dac770d

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

‎stdlib/@tests/stubtest_allowlists/common.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,10 @@ importlib.metadata._meta.SimplePath.joinpath # Runtime definition of protocol i
291291
inspect.Parameter.__init__
292292
inspect.Signature.__init__
293293

294+
# Abstract methods that don't exist at runtime
295+
_io._IOBase.read
296+
_io._IOBase.write
297+
294298
logging.LogRecord.__setattr__ # doesn't exist, but makes things easy if we pretend it does
295299

296300
# Iterable classes that don't define __iter__ at runtime (usually iterable via __getitem__)

‎stdlib/_io.pyi‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import builtins
22
import codecs
33
import sys
44
from _typeshed import FileDescriptorOrPath, MaybeNone, ReadableBuffer, WriteableBuffer
5-
from collections.abc import Callable, Iterable, Iterator
5+
from collections.abc import Iterable, Iterator
66
from io import BufferedIOBase, RawIOBase, TextIOBase, UnsupportedOperation as UnsupportedOperation
77
from os import _Opener
88
from types import TracebackType
@@ -36,14 +36,16 @@ if sys.version_info >= (3, 12):
3636
def flush(self) -> None: ...
3737
def isatty(self) -> bool: ...
3838
def readable(self) -> bool: ...
39-
read: Callable[..., Any]
39+
# Abstract method that doesn't exist at runtime, the exact return type depends on the sub-class
40+
def read(self, size: int = ..., /) -> Any: ...
4041
def readlines(self, hint: int = -1, /) -> list[bytes]: ...
4142
def seek(self, offset: int, whence: int = 0, /) -> int: ...
4243
def seekable(self) -> bool: ...
4344
def tell(self) -> int: ...
4445
def truncate(self, size: int | None = None, /) -> int: ...
4546
def writable(self) -> bool: ...
46-
write: Callable[..., Any]
47+
# Abstract method that doesn't exist at runtime, the exact arguments and return type depend on the sub-class
48+
def write(self, s: Any, /) -> Any: ...
4749
def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: ...
4850
def readline(self, size: int | None = -1, /) -> bytes: ...
4951
def __del__(self) -> None: ...
@@ -64,14 +66,16 @@ else:
6466
def flush(self) -> None: ...
6567
def isatty(self) -> bool: ...
6668
def readable(self) -> bool: ...
67-
read: Callable[..., Any]
69+
# Abstract method that doesn't exist at runtime, the exact arguments and return type depend on the sub-class
70+
def read(self) -> Any: ...
6871
def readlines(self, hint: int = -1, /) -> list[bytes]: ...
6972
def seek(self, offset: int, whence: int = 0, /) -> int: ...
7073
def seekable(self) -> bool: ...
7174
def tell(self) -> int: ...
7275
def truncate(self, size: int | None = None, /) -> int: ...
7376
def writable(self) -> bool: ...
74-
write: Callable[..., Any]
77+
# Abstract method that doesn't exist at runtime, the exact arguments and return type depend on the sub-class
78+
def write(self, s: Any, /) -> Any: ...
7579
def writelines(self, lines: Iterable[ReadableBuffer], /) -> None: ...
7680
def readline(self, size: int | None = -1, /) -> bytes: ...
7781
def __del__(self) -> None: ...

0 commit comments

Comments
 (0)