From 415d3870095a634ca8da6dddf5df03b449740d98 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 5 Dec 2021 20:06:22 +0000 Subject: [PATCH] Make various `os` functions available on Windows (#6500) --- stdlib/os/__init__.pyi | 20 ++++++++++---------- tests/stubtest_allowlists/darwin.txt | 3 --- tests/stubtest_allowlists/linux.txt | 3 --- tests/stubtest_allowlists/py3_common.txt | 3 +++ tests/stubtest_allowlists/win32-py310.txt | 1 - tests/stubtest_allowlists/win32-py39.txt | 14 -------------- tests/stubtest_allowlists/win32.txt | 3 --- 7 files changed, 13 insertions(+), 34 deletions(-) diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index fc0af0d47..94d56a167 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -416,6 +416,13 @@ def getpid() -> int: ... def getppid() -> int: ... def strerror(__code: int) -> str: ... def umask(__mask: int) -> int: ... +@final +class uname_result(NamedTuple): + sysname: str + nodename: str + release: str + version: str + machine: str if sys.platform != "win32": def ctermid() -> str: ... @@ -447,13 +454,6 @@ if sys.platform != "win32": def getsid(__pid: int) -> int: ... def setsid() -> None: ... def setuid(__uid: int) -> None: ... - @final - class uname_result(NamedTuple): - sysname: str - nodename: str - release: str - version: str - machine: str def uname() -> uname_result: ... @overload @@ -469,7 +469,7 @@ if sys.platform != "win32": def putenv(__name: bytes | str, __value: bytes | str) -> None: ... -if sys.platform != "win32": +if sys.platform != "win32" or sys.version_info >= (3, 9): def unsetenv(__name: bytes | str) -> None: ... _Opener = Callable[[str, int], int] @@ -563,7 +563,9 @@ else: def dup2(fd: int, fd2: int, inheritable: bool = ...) -> None: ... def fstat(fd: int) -> stat_result: ... +def ftruncate(__fd: int, __length: int) -> None: ... def fsync(fd: FileDescriptorLike) -> None: ... +def isatty(__fd: int) -> bool: ... def lseek(__fd: int, __position: int, __how: int) -> int: ... def open(path: StrOrBytesPath, flags: int, mode: int = ..., *, dir_fd: int | None = ...) -> int: ... def pipe() -> tuple[int, int]: ... @@ -577,10 +579,8 @@ if sys.platform != "win32": def fdatasync(fd: FileDescriptorLike) -> None: ... # Unix only, not Mac def fpathconf(__fd: int, __name: str | int) -> int: ... def fstatvfs(__fd: int) -> statvfs_result: ... - def ftruncate(__fd: int, __length: int) -> None: ... def get_blocking(__fd: int) -> bool: ... def set_blocking(__fd: int, __blocking: bool) -> None: ... - def isatty(__fd: int) -> bool: ... def lockf(__fd: int, __command: int, __length: int) -> None: ... def openpty() -> tuple[int, int]: ... # some flavors of Unix if sys.platform != "darwin": diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index 72e3a0977..a22f178e1 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -57,9 +57,6 @@ grp.struct_group.n_unnamed_fields mimetypes.MimeTypes.read_windows_registry os.ST_NOSUID os.ST_RDONLY -(os|posix).uname_result.n_fields -(os|posix).uname_result.n_sequence_fields -(os|posix).uname_result.n_unnamed_fields posix.chflags posix.dup2 posix.lchflags diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index 57b2e6f01..1bcea1d49 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -62,9 +62,6 @@ mimetypes.MimeTypes.read_windows_registry (os|posix).sched_param.n_fields (os|posix).sched_param.n_sequence_fields (os|posix).sched_param.n_unnamed_fields -(os|posix).uname_result.n_fields -(os|posix).uname_result.n_sequence_fields -(os|posix).uname_result.n_unnamed_fields (os|posix).waitid_result.n_fields (os|posix).waitid_result.n_sequence_fields (os|posix).waitid_result.n_unnamed_fields diff --git a/tests/stubtest_allowlists/py3_common.txt b/tests/stubtest_allowlists/py3_common.txt index 1c4a906a9..880c6ef0c 100644 --- a/tests/stubtest_allowlists/py3_common.txt +++ b/tests/stubtest_allowlists/py3_common.txt @@ -581,6 +581,9 @@ multiprocessing.synchronize.Semaphore.get_value (os|posix).times_result.n_fields (os|posix).times_result.n_sequence_fields (os|posix).times_result.n_unnamed_fields +(os|posix).uname_result.n_fields +(os|posix).uname_result.n_sequence_fields +(os|posix).uname_result.n_unnamed_fields pickle.Pickler.memo pickle.Unpickler.memo pipes.Template.makepipeline diff --git a/tests/stubtest_allowlists/win32-py310.txt b/tests/stubtest_allowlists/win32-py310.txt index 392071a0b..c57296600 100644 --- a/tests/stubtest_allowlists/win32-py310.txt +++ b/tests/stubtest_allowlists/win32-py310.txt @@ -16,6 +16,5 @@ asyncio.IocpProactor.sendto asyncio.windows_events.IocpProactor.recvfrom asyncio.windows_events.IocpProactor.sendto msvcrt.GetErrorMode -os.unsetenv socket.MsgFlag.MSG_ERRQUEUE subprocess.STARTUPINFO.copy diff --git a/tests/stubtest_allowlists/win32-py39.txt b/tests/stubtest_allowlists/win32-py39.txt index 65ee9f275..b351653ef 100644 --- a/tests/stubtest_allowlists/win32-py39.txt +++ b/tests/stubtest_allowlists/win32-py39.txt @@ -1,17 +1,4 @@ -# Missing from stubs, found by removing --ignore-missing-stub -_winapi.CreateFileMapping -_winapi.MapViewOfFile -_winapi.OpenFileMapping -_winapi.VirtualQuerySize -asyncio.IocpProactor.recvfrom -asyncio.IocpProactor.sendto -asyncio.windows_events.IocpProactor.recvfrom -asyncio.windows_events.IocpProactor.sendto -os.unsetenv -socket.MsgFlag.MSG_ERRQUEUE -subprocess.STARTUPINFO.copy - # Exists at runtime, but missing from stubs _winapi.CreateFileMapping _winapi.MapViewOfFile @@ -21,6 +8,5 @@ asyncio.IocpProactor.recvfrom asyncio.IocpProactor.sendto asyncio.windows_events.IocpProactor.recvfrom asyncio.windows_events.IocpProactor.sendto -os.unsetenv socket.MsgFlag.MSG_ERRQUEUE subprocess.STARTUPINFO.copy diff --git a/tests/stubtest_allowlists/win32.txt b/tests/stubtest_allowlists/win32.txt index 962c05a2e..f2663110e 100644 --- a/tests/stubtest_allowlists/win32.txt +++ b/tests/stubtest_allowlists/win32.txt @@ -46,12 +46,9 @@ distutils.msvccompiler.MSVCCompiler.manifest_get_embed_info distutils.msvccompiler.MSVCCompiler.manifest_setup_ldargs distutils.msvccompiler.OldMSVCCompiler msvcrt.SetErrorMode -os.ftruncate os.get_handle_inheritable -os.isatty os.set_handle_inheritable os.statvfs_result -os.uname_result signal.Signals.CTRL_BREAK_EVENT signal.Signals.CTRL_C_EVENT socket.MsgFlag.MSG_BCAST