From b9640005eb586afdbe0a57bac2b88a7a12465069 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 19 Oct 2023 18:16:06 +0100 Subject: [PATCH] Add stubs for `nt` (#10917) --- stdlib/VERSIONS | 1 + stdlib/nt.pyi | 111 +++++++++++++++++++++++++++ tests/stubtest_allowlists/darwin.txt | 1 + tests/stubtest_allowlists/linux.txt | 1 + tests/stubtest_allowlists/win32.txt | 1 - 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 stdlib/nt.pyi diff --git a/stdlib/VERSIONS b/stdlib/VERSIONS index 62c58a64266f..3ae2d8e50196 100644 --- a/stdlib/VERSIONS +++ b/stdlib/VERSIONS @@ -181,6 +181,7 @@ multiprocessing.shared_memory: 3.8- netrc: 2.7- nis: 2.7- nntplib: 2.7- +nt: 2.7- ntpath: 2.7- nturl2path: 2.7- numbers: 2.7- diff --git a/stdlib/nt.pyi b/stdlib/nt.pyi new file mode 100644 index 000000000000..4066096f4c71 --- /dev/null +++ b/stdlib/nt.pyi @@ -0,0 +1,111 @@ +import sys + +if sys.platform == "win32": + # Actually defined here and re-exported from os at runtime, + # but this leads to less code duplication + from os import ( + F_OK as F_OK, + O_APPEND as O_APPEND, + O_BINARY as O_BINARY, + O_CREAT as O_CREAT, + O_EXCL as O_EXCL, + O_NOINHERIT as O_NOINHERIT, + O_RANDOM as O_RANDOM, + O_RDONLY as O_RDONLY, + O_RDWR as O_RDWR, + O_SEQUENTIAL as O_SEQUENTIAL, + O_SHORT_LIVED as O_SHORT_LIVED, + O_TEMPORARY as O_TEMPORARY, + O_TEXT as O_TEXT, + O_TRUNC as O_TRUNC, + O_WRONLY as O_WRONLY, + P_DETACH as P_DETACH, + P_NOWAIT as P_NOWAIT, + P_NOWAITO as P_NOWAITO, + P_OVERLAY as P_OVERLAY, + P_WAIT as P_WAIT, + R_OK as R_OK, + TMP_MAX as TMP_MAX, + W_OK as W_OK, + X_OK as X_OK, + DirEntry as DirEntry, + abort as abort, + access as access, + chdir as chdir, + chmod as chmod, + close as close, + closerange as closerange, + cpu_count as cpu_count, + device_encoding as device_encoding, + dup as dup, + dup2 as dup2, + error as error, + execv as execv, + execve as execve, + fspath as fspath, + fstat as fstat, + fsync as fsync, + ftruncate as ftruncate, + get_handle_inheritable as get_handle_inheritable, + get_inheritable as get_inheritable, + get_terminal_size as get_terminal_size, + getcwd as getcwd, + getcwdb as getcwdb, + getlogin as getlogin, + getpid as getpid, + getppid as getppid, + isatty as isatty, + kill as kill, + link as link, + listdir as listdir, + lseek as lseek, + lstat as lstat, + mkdir as mkdir, + open as open, + pipe as pipe, + putenv as putenv, + read as read, + readlink as readlink, + remove as remove, + rename as rename, + replace as replace, + rmdir as rmdir, + scandir as scandir, + set_handle_inheritable as set_handle_inheritable, + set_inheritable as set_inheritable, + spawnv as spawnv, + spawnve as spawnve, + startfile as startfile, + stat as stat, + stat_result as stat_result, + statvfs_result as statvfs_result, + strerror as strerror, + symlink as symlink, + system as system, + terminal_size as terminal_size, + times as times, + times_result as times_result, + truncate as truncate, + umask as umask, + uname_result as uname_result, + unlink as unlink, + urandom as urandom, + utime as utime, + waitpid as waitpid, + write as write, + ) + + if sys.version_info >= (3, 9): + from os import unsetenv as unsetenv, waitstatus_to_exitcode as waitstatus_to_exitcode + if sys.version_info >= (3, 11): + from os import EX_OK as EX_OK + if sys.version_info >= (3, 12): + from os import ( + get_blocking as get_blocking, + listdrives as listdrives, + listmounts as listmounts, + listvolumes as listvolumes, + set_blocking as set_blocking, + ) + + environ: dict[str, str] diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index 1d5283ca5df1..014846d7c359 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -40,6 +40,7 @@ asyncio.windows_events asyncio.windows_utils msilib(.[a-z]+)? msvcrt +nt winreg winsound ossaudiodev diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index cb7997a11af7..3e1993135f08 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -29,6 +29,7 @@ asyncio.windows_events asyncio.windows_utils msilib(.[a-z]+)? msvcrt +nt winreg winsound diff --git a/tests/stubtest_allowlists/win32.txt b/tests/stubtest_allowlists/win32.txt index 1f3bc656ab95..0c783bea5909 100644 --- a/tests/stubtest_allowlists/win32.txt +++ b/tests/stubtest_allowlists/win32.txt @@ -6,7 +6,6 @@ multiprocessing.reduction.AbstractReducer.DupHandle # Exists at runtime, but missing from stubs encodings.mbcs encodings.oem -nt _winapi.CreateFileMapping _winapi.MapViewOfFile _winapi.OpenFileMapping