|
| 1 | +import io |
1 | 2 | import os
|
2 | 3 | import sys
|
3 |
| -from _typeshed import Self |
| 4 | +from _typeshed import Self, WriteableBuffer |
4 | 5 | from collections.abc import Iterable, Iterator
|
5 | 6 | from types import TracebackType
|
6 | 7 | from typing import IO, Any, AnyStr, Generic, overload
|
@@ -217,9 +218,14 @@ class _TemporaryFileWrapper(Generic[AnyStr], IO[AnyStr]):
|
217 | 218 | def write(self, s: AnyStr) -> int: ...
|
218 | 219 | def writelines(self, lines: Iterable[AnyStr]) -> None: ...
|
219 | 220 |
|
220 |
| -# It does not actually derive from IO[AnyStr], but it does implement the |
221 |
| -# protocol. |
222 |
| -class SpooledTemporaryFile(IO[AnyStr]): |
| 221 | +if sys.version_info >= (3, 11): |
| 222 | + _SpooledTemporaryFileBase = io.IOBase |
| 223 | +else: |
| 224 | + _SpooledTemporaryFileBase = object |
| 225 | + |
| 226 | +# It does not actually derive from IO[AnyStr], but it does mostly behave |
| 227 | +# like one. |
| 228 | +class SpooledTemporaryFile(IO[AnyStr], _SpooledTemporaryFileBase): |
223 | 229 | @property
|
224 | 230 | def encoding(self) -> str: ... # undocumented
|
225 | 231 | @property
|
@@ -318,20 +324,28 @@ class SpooledTemporaryFile(IO[AnyStr]):
|
318 | 324 | def fileno(self) -> int: ...
|
319 | 325 | def flush(self) -> None: ...
|
320 | 326 | def isatty(self) -> bool: ...
|
321 |
| - def read(self, n: int = ...) -> AnyStr: ... |
322 |
| - def readline(self, limit: int = ...) -> AnyStr: ... |
323 |
| - def readlines(self, hint: int = ...) -> list[AnyStr]: ... |
| 327 | + if sys.version_info >= (3, 11): |
| 328 | + # These three work only if the SpooledTemporaryFile is opened in binary mode, |
| 329 | + # because the underlying object in text mode does not have these methods. |
| 330 | + def read1(self, __size: int = ...) -> AnyStr: ... |
| 331 | + def readinto(self, b: WriteableBuffer) -> int: ... |
| 332 | + def readinto1(self, b: WriteableBuffer) -> int: ... |
| 333 | + def detach(self) -> io.RawIOBase: ... |
| 334 | + |
| 335 | + def read(self, __n: int = ...) -> AnyStr: ... |
| 336 | + def readline(self, __limit: int | None = ...) -> AnyStr: ... # type: ignore[override] |
| 337 | + def readlines(self, __hint: int = ...) -> list[AnyStr]: ... # type: ignore[override] |
324 | 338 | def seek(self, offset: int, whence: int = ...) -> int: ...
|
325 | 339 | def tell(self) -> int: ...
|
326 | 340 | def truncate(self, size: int | None = ...) -> None: ... # type: ignore[override]
|
327 | 341 | def write(self, s: AnyStr) -> int: ...
|
328 |
| - def writelines(self, iterable: Iterable[AnyStr]) -> None: ... |
329 |
| - def __iter__(self) -> Iterator[AnyStr]: ... |
330 |
| - # Other than the following methods, which do not exist on SpooledTemporaryFile |
| 342 | + def writelines(self, iterable: Iterable[AnyStr]) -> None: ... # type: ignore[override] |
| 343 | + def __iter__(self) -> Iterator[AnyStr]: ... # type: ignore[override] |
| 344 | + # These exist at runtime only on 3.11+. |
331 | 345 | def readable(self) -> bool: ...
|
332 | 346 | def seekable(self) -> bool: ...
|
333 | 347 | def writable(self) -> bool: ...
|
334 |
| - def __next__(self) -> AnyStr: ... |
| 348 | + def __next__(self) -> AnyStr: ... # type: ignore[override] |
335 | 349 | if sys.version_info >= (3, 9):
|
336 | 350 | def __class_getitem__(cls, item: Any) -> GenericAlias: ...
|
337 | 351 |
|
|
0 commit comments