tempfile.SpooledTemporaryFile: inherit from IOBase on 3.11 (#7802)

python/cpython#29560

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
This commit is contained in:
Jelle Zijlstra
2022-05-17 18:41:47 -07:00
committed by GitHub
parent eab82c838a
commit 8f5a83516b
2 changed files with 25 additions and 15 deletions

View File

@@ -1,6 +1,7 @@
import io
import os
import sys
from _typeshed import Self
from _typeshed import Self, WriteableBuffer
from collections.abc import Iterable, Iterator
from types import TracebackType
from typing import IO, Any, AnyStr, Generic, overload
@@ -217,9 +218,14 @@ class _TemporaryFileWrapper(Generic[AnyStr], IO[AnyStr]):
def write(self, s: AnyStr) -> int: ...
def writelines(self, lines: Iterable[AnyStr]) -> None: ...
# It does not actually derive from IO[AnyStr], but it does implement the
# protocol.
class SpooledTemporaryFile(IO[AnyStr]):
if sys.version_info >= (3, 11):
_SpooledTemporaryFileBase = io.IOBase
else:
_SpooledTemporaryFileBase = object
# It does not actually derive from IO[AnyStr], but it does mostly behave
# like one.
class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase):
@property
def encoding(self) -> str: ... # undocumented
@property
@@ -318,20 +324,28 @@ class SpooledTemporaryFile(IO[AnyStr]):
def fileno(self) -> int: ...
def flush(self) -> None: ...
def isatty(self) -> bool: ...
def read(self, n: int = ...) -> AnyStr: ...
def readline(self, limit: int = ...) -> AnyStr: ...
def readlines(self, hint: int = ...) -> list[AnyStr]: ...
if sys.version_info >= (3, 11):
# These three work only if the SpooledTemporaryFile is opened in binary mode,
# because the underlying object in text mode does not have these methods.
def read1(self, __size: int = ...) -> AnyStr: ...
def readinto(self, b: WriteableBuffer) -> int: ...
def readinto1(self, b: WriteableBuffer) -> int: ...
def detach(self) -> io.RawIOBase: ...
def read(self, __n: int = ...) -> AnyStr: ...
def readline(self, __limit: int | None = ...) -> AnyStr: ... # type: ignore[override]
def readlines(self, __hint: int = ...) -> list[AnyStr]: ... # type: ignore[override]
def seek(self, offset: int, whence: int = ...) -> int: ...
def tell(self) -> int: ...
def truncate(self, size: int | None = ...) -> None: ... # type: ignore[override]
def write(self, s: AnyStr) -> int: ...
def writelines(self, iterable: Iterable[AnyStr]) -> None: ...
def __iter__(self) -> Iterator[AnyStr]: ...
# Other than the following methods, which do not exist on SpooledTemporaryFile
def writelines(self, iterable: Iterable[AnyStr]) -> None: ... # type: ignore[override]
def __iter__(self) -> Iterator[AnyStr]: ... # type: ignore[override]
# These exist at runtime only on 3.11+.
def readable(self) -> bool: ...
def seekable(self) -> bool: ...
def writable(self) -> bool: ...
def __next__(self) -> AnyStr: ...
def __next__(self) -> AnyStr: ... # type: ignore[override]
if sys.version_info >= (3, 9):
def __class_getitem__(cls, item: Any) -> GenericAlias: ...