diff --git a/stdlib/@tests/stubtest_allowlists/common.txt b/stdlib/@tests/stubtest_allowlists/common.txt index 36b7bf39b6c9..413fa4f135e4 100644 --- a/stdlib/@tests/stubtest_allowlists/common.txt +++ b/stdlib/@tests/stubtest_allowlists/common.txt @@ -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 diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index d7bb4883a0f2..c7a413a55b2e 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -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, @@ -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 ----- @@ -578,7 +580,7 @@ def fdopen( newline: str | None = ..., closefd: bool = ..., opener: _Opener | None = ..., -) -> _TextIOWrapper: ... +) -> TextIOWrapper: ... @overload def fdopen( fd: int, @@ -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