Skip to content
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

Fix stub for SpooledTemporaryFile #2452

Merged
merged 7 commits into from
Nov 20, 2018
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 54 additions & 7 deletions stdlib/3/tempfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
# based on http://docs.python.org/3.3/library/tempfile.html

import sys
from abc import abstractmethod
from types import TracebackType
from typing import Any, AnyStr, Generic, IO, Optional, Tuple, Type
from typing import Any, AnyStr, Generic, IO, Iterable, Iterator, Optional, Tuple, Type

# global variables
TMP_MAX: int
Expand All @@ -26,12 +27,58 @@ if sys.version_info >= (3, 5):
dir: Optional[AnyStr] = ..., delete: bool =...
) -> IO[Any]:
...
def SpooledTemporaryFile(
max_size: int = ..., mode: str = ..., buffering: int = ...,
encoding: str = ..., newline: str = ..., suffix: Optional[AnyStr] = ...,
prefix: Optional[AnyStr] = ..., dir: Optional[AnyStr] = ...
) -> IO[Any]:
...

# It does not actually derive from IO[Any], but it does implement the
# protocol.
class SpooledTemporaryFile(IO[Any]):
srittau marked this conversation as resolved.
Show resolved Hide resolved
def __init__(self, max_size: int = ..., mode: str = ...,
buffering: int = ..., encoding: Optional[str] = ...,
newline: Optional[str] = ..., suffix: Optional[str] = ...,
prefix: Optional[str] = ..., dir: Optional[str] = ...
) -> None: ...
def rollover(self) -> None: ...
def __enter__(self) -> SpooledTemporaryFile: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[BaseException],
exc_tb: Optional[TracebackType]) -> bool: ...

# These abstract methods are copied from IO, because
# SpooledTemporaryFile implements IO.
# See also https://github.com/python/typeshed/pull/2452#issuecomment-420657918.
@abstractmethod
def close(self) -> None: ...
@abstractmethod
def fileno(self) -> int: ...
@abstractmethod
def flush(self) -> None: ...
@abstractmethod
def isatty(self) -> bool: ...
@abstractmethod
def read(self, n: int = ...) -> AnyStr: ...
@abstractmethod
def readable(self) -> bool: ...
@abstractmethod
def readline(self, limit: int = ...) -> AnyStr: ...
@abstractmethod
def readlines(self, hint: int = ...) -> list[AnyStr]: ...
srittau marked this conversation as resolved.
Show resolved Hide resolved
@abstractmethod
def seek(self, offset: int, whence: int = ...) -> int: ...
@abstractmethod
def seekable(self) -> bool: ...
@abstractmethod
def tell(self) -> int: ...
@abstractmethod
def truncate(self, size: Optional[int] = ...) -> int: ...
@abstractmethod
def writable(self) -> bool: ...
@abstractmethod
def write(self, s: AnyStr) -> int: ...
@abstractmethod
def writelines(self, lines: Iterable[AnyStr]) -> None: ...
@abstractmethod
def __next__(self) -> AnyStr: ...
@abstractmethod
def __iter__(self) -> Iterator[AnyStr]: ...

class TemporaryDirectory(Generic[AnyStr]):
name = ... # type: str
Expand Down