diff --git a/stdlib/3/tempfile.pyi b/stdlib/3/tempfile.pyi index 7b87fd46e..7dd680321 100644 --- a/stdlib/3/tempfile.pyi +++ b/stdlib/3/tempfile.pyi @@ -164,6 +164,39 @@ else: dir: Optional[_DirT[AnyStr]] = ..., ) -> IO[Any]: ... +class _TemporaryFileWrapper(IO[str]): + file: IO[str] + name: Any + delete: bool + def __init__(self, file: IO[str], name: Any, delete: bool = ...) -> None: ... + def __enter__(self) -> _TemporaryFileWrapper: ... + def __exit__( + self, exc: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType] + ) -> Optional[bool]: ... + def __getattr__(self, name: str) -> Any: ... + def close(self) -> None: ... + def unlink(self, path: str) -> None: ... + # These methods don't exist directly on this object, but + # are delegated to the underlying IO object through __getattr__. + # We need to add them here so that this class is concrete. + def __iter__(self) -> Iterator[str]: ... + def __next__(self) -> str: ... + def fileno(self) -> int: ... + def flush(self) -> None: ... + def isatty(self) -> bool: ... + def next(self) -> str: ... + def read(self, n: int = ...) -> str: ... + def readable(self) -> bool: ... + def readline(self, limit: int = ...) -> str: ... + def readlines(self, hint: int = ...) -> List[str]: ... + def seek(self, offset: int, whence: int = ...) -> int: ... + def seekable(self) -> bool: ... + def tell(self) -> int: ... + def truncate(self, size: Optional[int] = ...) -> int: ... + def writable(self) -> bool: ... + def write(self, s: str) -> int: ... + def writelines(self, lines: Iterable[str]) -> None: ... + # It does not actually derive from IO[AnyStr], but it does implement the # protocol. class SpooledTemporaryFile(IO[AnyStr]): diff --git a/tests/stubtest_whitelists/py3_common.txt b/tests/stubtest_whitelists/py3_common.txt index 9f49cd6cf..2fb874204 100644 --- a/tests/stubtest_whitelists/py3_common.txt +++ b/tests/stubtest_whitelists/py3_common.txt @@ -455,6 +455,8 @@ builtins.quit builtins.reveal_locals builtins.reveal_type collections.abc.* # Types are re-exported from _collections_abc, so errors should be fixed there +# Dynamically specified by __getattr__, and thus don't exist on the class +tempfile._TemporaryFileWrapper.[\w_]+ # Various classes in typing aren't types at runtime. In addition, mypy thinks some special forms are tautologically defined. typing.[A-Z]\w+ # We can't distinguish not having a default value from having a default value of inspect.Parameter.empty