From 0a6b6b095c3c384317fb4cc7ba2a8fa98db8bf66 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Wed, 2 Mar 2022 02:37:54 -0800 Subject: [PATCH] Add asyncio.windows_utils.Popen (#7396) --- stdlib/asyncio/windows_utils.pyi | 27 ++++++++++++++++++++++++++- tests/stubtest_allowlists/win32.txt | 1 - 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/stdlib/asyncio/windows_utils.pyi b/stdlib/asyncio/windows_utils.pyi index 78eff6956..35a44be50 100644 --- a/stdlib/asyncio/windows_utils.pyi +++ b/stdlib/asyncio/windows_utils.pyi @@ -2,7 +2,7 @@ import subprocess import sys from _typeshed import Self from types import TracebackType -from typing import Callable, Protocol +from typing import Any, AnyStr, Callable, Protocol from typing_extensions import Literal if sys.platform == "win32": @@ -36,3 +36,28 @@ if sys.platform == "win32": def handle(self) -> int: ... def fileno(self) -> int: ... def close(self, *, CloseHandle: Callable[[int], None] = ...) -> None: ... + + class Popen(subprocess.Popen[AnyStr]): + stdin: PipeHandle | None # type: ignore[assignment] + stdout: PipeHandle | None # type: ignore[assignment] + stderr: PipeHandle | None # type: ignore[assignment] + # For simplicity we omit the full overloaded __new__ signature of + # subprocess.Popen. The arguments are mostly the same, but + # subprocess.Popen takes other positional-or-keyword arguments before + # stdin. + def __new__( + cls: type[Self], + args: subprocess._CMD, + stdin: subprocess._FILE | None = ..., + stdout: subprocess._FILE | None = ..., + stderr: subprocess._FILE | None = ..., + **kwds: Any, + ) -> Self: ... + def __init__( + self, + args: subprocess._CMD, + stdin: subprocess._FILE | None = ..., + stdout: subprocess._FILE | None = ..., + stderr: subprocess._FILE | None = ..., + **kwds: Any, + ) -> None: ... diff --git a/tests/stubtest_allowlists/win32.txt b/tests/stubtest_allowlists/win32.txt index 6f25a3ad7..6e30e679b 100644 --- a/tests/stubtest_allowlists/win32.txt +++ b/tests/stubtest_allowlists/win32.txt @@ -65,7 +65,6 @@ pathlib.Path.group # Exists at runtime, but missing from stubs _msi.MSIError -asyncio.windows_utils.Popen distutils.msvccompiler.MSVCCompiler.manifest_get_embed_info distutils.msvccompiler.MSVCCompiler.manifest_setup_ldargs distutils.msvccompiler.OldMSVCCompiler