Skip to content

Commit 6870caf

Browse files
authored
Add _TemporaryFileWrapper (#4559)
1 parent 58032a7 commit 6870caf

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

stdlib/3/tempfile.pyi

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,39 @@ else:
164164
dir: Optional[_DirT[AnyStr]] = ...,
165165
) -> IO[Any]: ...
166166

167+
class _TemporaryFileWrapper(IO[str]):
168+
file: IO[str]
169+
name: Any
170+
delete: bool
171+
def __init__(self, file: IO[str], name: Any, delete: bool = ...) -> None: ...
172+
def __enter__(self) -> _TemporaryFileWrapper: ...
173+
def __exit__(
174+
self, exc: Optional[Type[BaseException]], value: Optional[BaseException], tb: Optional[TracebackType]
175+
) -> Optional[bool]: ...
176+
def __getattr__(self, name: str) -> Any: ...
177+
def close(self) -> None: ...
178+
def unlink(self, path: str) -> None: ...
179+
# These methods don't exist directly on this object, but
180+
# are delegated to the underlying IO object through __getattr__.
181+
# We need to add them here so that this class is concrete.
182+
def __iter__(self) -> Iterator[str]: ...
183+
def __next__(self) -> str: ...
184+
def fileno(self) -> int: ...
185+
def flush(self) -> None: ...
186+
def isatty(self) -> bool: ...
187+
def next(self) -> str: ...
188+
def read(self, n: int = ...) -> str: ...
189+
def readable(self) -> bool: ...
190+
def readline(self, limit: int = ...) -> str: ...
191+
def readlines(self, hint: int = ...) -> List[str]: ...
192+
def seek(self, offset: int, whence: int = ...) -> int: ...
193+
def seekable(self) -> bool: ...
194+
def tell(self) -> int: ...
195+
def truncate(self, size: Optional[int] = ...) -> int: ...
196+
def writable(self) -> bool: ...
197+
def write(self, s: str) -> int: ...
198+
def writelines(self, lines: Iterable[str]) -> None: ...
199+
167200
# It does not actually derive from IO[AnyStr], but it does implement the
168201
# protocol.
169202
class SpooledTemporaryFile(IO[AnyStr]):

tests/stubtest_whitelists/py3_common.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,8 @@ builtins.quit
455455
builtins.reveal_locals
456456
builtins.reveal_type
457457
collections.abc.* # Types are re-exported from _collections_abc, so errors should be fixed there
458+
# Dynamically specified by __getattr__, and thus don't exist on the class
459+
tempfile._TemporaryFileWrapper.[\w_]+
458460
# Various classes in typing aren't types at runtime. In addition, mypy thinks some special forms are tautologically defined.
459461
typing.[A-Z]\w+
460462
# We can't distinguish not having a default value from having a default value of inspect.Parameter.empty

0 commit comments

Comments
 (0)