From d9faffc80e86f7826e00ffcb75fc9af5b4605972 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 9 Oct 2024 15:42:14 -0700 Subject: [PATCH 1/2] remove redundant methods from _io classes --- stdlib/_io.pyi | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/stdlib/_io.pyi b/stdlib/_io.pyi index ed893679aa37..c3ff8b073e30 100644 --- a/stdlib/_io.pyi +++ b/stdlib/_io.pyi @@ -73,7 +73,6 @@ class FileIO(RawIOBase, _RawIOBase, BinaryIO): # type: ignore[misc] # incompat ) -> None: ... @property def closefd(self) -> bool: ... - def __enter__(self) -> Self: ... class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes def __init__(self, initial_bytes: ReadableBuffer = ...) -> None: ... @@ -81,25 +80,21 @@ class BytesIO(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # to allow BytesIO sub-classes to add this field, as it is defined # as a read-only property on IO[]. name: Any - def __enter__(self) -> Self: ... def getvalue(self) -> bytes: ... def getbuffer(self) -> memoryview: ... def read1(self, size: int | None = -1, /) -> bytes: ... class BufferedReader(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of methods in the base classes raw: RawIOBase - def __enter__(self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def peek(self, size: int = 0, /) -> bytes: ... class BufferedWriter(BufferedIOBase, _BufferedIOBase, BinaryIO): # type: ignore[misc] # incompatible definitions of writelines in the base classes raw: RawIOBase - def __enter__(self) -> Self: ... def __init__(self, raw: RawIOBase, buffer_size: int = ...) -> None: ... def write(self, buffer: ReadableBuffer, /) -> int: ... class BufferedRandom(BufferedReader, BufferedWriter, BufferedIOBase, _BufferedIOBase): # type: ignore[misc] # incompatible definitions of methods in the base classes - def __enter__(self) -> Self: ... def seek(self, target: int, whence: int = 0, /) -> int: ... # stubtest needs this class BufferedRWPair(BufferedIOBase, _BufferedIOBase): @@ -159,8 +154,6 @@ class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # t @property def buffer(self) -> _BufferT_co: ... # type: ignore[override] @property - def closed(self) -> bool: ... - @property def line_buffering(self) -> bool: ... @property def write_through(self) -> bool: ... @@ -173,19 +166,15 @@ class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # t line_buffering: bool | None = None, write_through: bool | None = None, ) -> None: ... - # These are inherited from TextIOBase, but must exist in the stub to satisfy mypy. - def __enter__(self) -> Self: ... - def __iter__(self) -> Iterator[str]: ... # type: ignore[override] - def __next__(self) -> str: ... # type: ignore[override] - def writelines(self, lines: Iterable[str], /) -> None: ... # type: ignore[override] def readline(self, size: int = -1, /) -> str: ... # type: ignore[override] - def readlines(self, hint: int = -1, /) -> list[str]: ... # type: ignore[override] # Equals the "buffer" argument passed in to the constructor. def detach(self) -> _BufferT_co: ... # type: ignore[override] # TextIOWrapper's version of seek only supports a limited subset of # operations. def seek(self, cookie: int, whence: int = 0, /) -> int: ... +# The C implementation is not a subclass of TextIOWrapper at runtime, +# but the implementation in _pyio is class StringIO(TextIOWrapper, TextIOBase, _TextIOBase): # type: ignore[misc] # incompatible definitions of write in the base classes def __init__(self, initial_value: str | None = ..., newline: str | None = ...) -> None: ... # StringIO does not contain a "name" field. This workaround is necessary @@ -194,6 +183,8 @@ class StringIO(TextIOWrapper, TextIOBase, _TextIOBase): # type: ignore[misc] # name: Any def getvalue(self) -> str: ... +# The C implementation is not a subclass of codecs.IncrementalDecoder at runtime +# but the implementation in _pyio is class IncrementalNewlineDecoder(codecs.IncrementalDecoder): def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ... def decode(self, input: ReadableBuffer | str, final: bool = False) -> str: ... From d1ff55a8f1ab2be1c43f758a1c0b62ebc0adb642 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Wed, 9 Oct 2024 19:01:08 -0700 Subject: [PATCH 2/2] remove comments tangential to this MR --- stdlib/_io.pyi | 4 ---- 1 file changed, 4 deletions(-) diff --git a/stdlib/_io.pyi b/stdlib/_io.pyi index c3ff8b073e30..e8290daad106 100644 --- a/stdlib/_io.pyi +++ b/stdlib/_io.pyi @@ -173,8 +173,6 @@ class TextIOWrapper(TextIOBase, _TextIOBase, TextIO, Generic[_BufferT_co]): # t # operations. def seek(self, cookie: int, whence: int = 0, /) -> int: ... -# The C implementation is not a subclass of TextIOWrapper at runtime, -# but the implementation in _pyio is class StringIO(TextIOWrapper, TextIOBase, _TextIOBase): # type: ignore[misc] # incompatible definitions of write in the base classes def __init__(self, initial_value: str | None = ..., newline: str | None = ...) -> None: ... # StringIO does not contain a "name" field. This workaround is necessary @@ -183,8 +181,6 @@ class StringIO(TextIOWrapper, TextIOBase, _TextIOBase): # type: ignore[misc] # name: Any def getvalue(self) -> str: ... -# The C implementation is not a subclass of codecs.IncrementalDecoder at runtime -# but the implementation in _pyio is class IncrementalNewlineDecoder(codecs.IncrementalDecoder): def __init__(self, decoder: codecs.IncrementalDecoder | None, translate: bool, errors: str = ...) -> None: ... def decode(self, input: ReadableBuffer | str, final: bool = False) -> str: ...