Skip to content

Draft: Wrap close test #12782

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
25 changes: 25 additions & 0 deletions stdlib/@tests/stubtest_allowlists/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,31 @@ tkinter.Place.place_slaves
tkinter.Place.slaves

# Methods that come from __getattr__() at runtime
os._wrap_close.__del__
os._wrap_close.buffer
os._wrap_close.closed
os._wrap_close.detach
os._wrap_close.encoding
os._wrap_close.errors
os._wrap_close.fileno
os._wrap_close.flush
os._wrap_close.isatty
os._wrap_close.line_buffering
os._wrap_close.name
os._wrap_close.newlines
os._wrap_close.read
os._wrap_close.readable
os._wrap_close.readline
os._wrap_close.readlines
os._wrap_close.reconfigure
os._wrap_close.seek
os._wrap_close.seekable
os._wrap_close.tell
os._wrap_close.truncate
os._wrap_close.writable
os._wrap_close.write
os._wrap_close.write_through
os._wrap_close.writelines
tkinter.Tk.adderrorinfo
tkinter.Tk.call
tkinter.Tk.createcommand
Expand Down
20 changes: 15 additions & 5 deletions stdlib/os/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ from abc import abstractmethod
from builtins import OSError
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping, Sequence
from contextlib import AbstractContextManager
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper as _TextIOWrapper
from io import BufferedRandom, BufferedReader, BufferedWriter, FileIO, TextIOWrapper, _WrappedBuffer
from subprocess import Popen
from types import TracebackType
from typing import (
IO,
Any,
Expand Down Expand Up @@ -53,6 +54,7 @@ path = _path
_T = TypeVar("_T")
_T1 = TypeVar("_T1")
_T2 = TypeVar("_T2")
_BufferT_co = TypeVar("_BufferT_co", bound=_WrappedBuffer, default=_WrappedBuffer, covariant=True)

# ----- os variables -----

Expand Down Expand Up @@ -578,7 +580,7 @@ def fdopen(
newline: str | None = ...,
closefd: bool = ...,
opener: _Opener | None = ...,
) -> _TextIOWrapper: ...
) -> TextIOWrapper: ...
@overload
def fdopen(
fd: int,
Expand Down Expand Up @@ -917,11 +919,19 @@ if sys.platform != "win32":
if sys.platform != "darwin" and sys.platform != "linux":
def plock(op: int, /) -> None: ...

class _wrap_close(_TextIOWrapper):
def __init__(self, stream: _TextIOWrapper, proc: Popen[str]) -> None: ...
class _wrap_close(Generic[_BufferT_co]):
def __init__(self, stream: TextIOWrapper, proc: Popen[str]) -> None: ...
def close(self) -> int | None: ... # type: ignore[override]
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
) -> None: ...
def __iter__(self) -> Iterator[str]: ...

def popen(cmd: str, mode: str = "r", buffering: int = -1) -> _wrap_close: ...
@overload
def popen(cmd: str, mode: Literal["r"] = "r", buffering: int = -1) -> _wrap_close[BufferedReader]: ...
@overload
def popen(cmd: str, mode: Literal["w"], buffering: int = -1) -> _wrap_close[BufferedWriter]: ...
def spawnl(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ...
def spawnle(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise sig

Expand Down
Loading