mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-19 18:31:14 +08:00
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:
@@ -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: ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user