Skip to content
32 changes: 22 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,26 @@ 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 detach(self) -> io.RawIOBase: ...

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
4 changes: 0 additions & 4 deletions tests/stubtest_allowlists/py311.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ subprocess.getstatusoutput
symtable.SymbolTable.has_exec
sys.UnraisableHookArgs # Not exported from sys
sys.exception
tempfile.SpooledTemporaryFile.detach
tempfile.SpooledTemporaryFile.read1
tempfile.SpooledTemporaryFile.readinto
tempfile.SpooledTemporaryFile.readinto1
tkinter._VersionInfoType.__doc__
traceback.StackSummary.format_frame_summary
traceback.TracebackException.__init__
Expand Down