Skip to content

tempfile.SpooledTemporaryFile: inherit from IOBase on 3.11 #7802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 18, 2022
31 changes: 21 additions & 10 deletions stdlib/tempfile.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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]):
# It does not actually derive from IO[AnyStr], but it does mostly behave
# like one.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should probably be moved down above the class itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if sys.version_info >= (3, 11):
_SpooledTemporaryFileBase = io.IOBase
else:
_SpooledTemporaryFileBase = object

class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase):
@property
def encoding(self) -> str: ... # undocumented
@property
Expand Down Expand Up @@ -318,20 +324,25 @@ class SpooledTemporaryFile(IO[AnyStr]):
def fileno(self) -> int: ...
def flush(self) -> None: ...
def isatty(self) -> bool: ...
if sys.version_info >= (3, 11):
def read1(self, __size: int = ...) -> AnyStr: ...
def readinto(self, b: WriteableBuffer) -> int: ...
def readinto1(self, b: WriteableBuffer) -> int: ...

def read(self, n: int = ...) -> AnyStr: ...
def readline(self, limit: int = ...) -> AnyStr: ...
def readlines(self, hint: int = ...) -> list[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: ...

Expand Down