diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 709902e86..5308416ad 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -90,6 +90,9 @@ if sys.platform != "win32": P_PGID: int P_ALL: int + if sys.platform == "linux" and sys.version_info >= (3, 9): + P_PIDFD: int + WEXITED: int WSTOPPED: int WNOWAIT: int @@ -99,6 +102,10 @@ if sys.platform != "win32": CLD_TRAPPED: int CLD_CONTINUED: int + if sys.version_info >= (3, 9): + CLD_KILLED: int + CLD_STOPPED: int + # TODO: SCHED_RESET_ON_FORK not available on darwin? # TODO: SCHED_BATCH and SCHED_IDLE are linux only? SCHED_OTHER: int # some flavors of Unix @@ -173,14 +180,14 @@ if sys.platform != "win32" and sys.platform != "darwin": ST_NODEV: int ST_NODIRATIME: int ST_NOEXEC: int - ST_NOSUID: int - ST_RDONLY: int ST_RELATIME: int ST_SYNCHRONOUS: int ST_WRITE: int if sys.platform != "win32": NGROUPS_MAX: int + ST_NOSUID: int + ST_RDONLY: int curdir: str pardir: str @@ -621,6 +628,16 @@ if sys.platform != "win32": def posix_fadvise(fd: int, offset: int, length: int, advice: int) -> None: ... def pread(__fd: int, __length: int, __offset: int) -> bytes: ... def pwrite(__fd: int, __buffer: bytes, __offset: int) -> int: ... + if sys.platform != "darwin": + if sys.version_info >= (3, 10): + RWF_APPEND: int # docs say available on 3.7+, stubtest says otherwise + if sys.version_info >= (3, 7): + def preadv(__fd: int, __buffers: Iterable[bytes], __offset: int, __flags: int = ...) -> int: ... + def pwritev(__fd: int, __buffers: Iterable[bytes], __offset: int, __flags: int = ...) -> int: ... + RWF_DSYNC: int + RWF_SYNC: int + RWF_HIPRI: int + RWF_NOWAIT: int @overload def sendfile(out_fd: int, in_fd: int, offset: int | None, count: int) -> int: ... @overload @@ -931,6 +948,9 @@ else: setsigdef: Iterable[int] = ..., scheduler: tuple[Any, sched_param] | None = ..., ) -> int: ... + POSIX_SPAWN_OPEN: int + POSIX_SPAWN_CLOSE: int + POSIX_SPAWN_DUP2: int if sys.platform != "win32": @final diff --git a/stdlib/posix.pyi b/stdlib/posix.pyi index cdca4235d..9f658039b 100644 --- a/stdlib/posix.pyi +++ b/stdlib/posix.pyi @@ -70,6 +70,8 @@ if sys.platform != "win32": SCHED_SPORADIC as SCHED_SPORADIC, SEEK_DATA as SEEK_DATA, SEEK_HOLE as SEEK_HOLE, + ST_NOSUID as ST_NOSUID, + ST_RDONLY as ST_RDONLY, TMP_MAX as TMP_MAX, W_OK as W_OK, WCONTINUED as WCONTINUED, @@ -264,10 +266,22 @@ if sys.platform != "win32": waitid_result as waitid_result, ) + if sys.version_info >= (3, 10): + from os import RWF_APPEND as RWF_APPEND + if sys.version_info >= (3, 9): - from os import waitstatus_to_exitcode as waitstatus_to_exitcode + from os import CLD_KILLED as CLD_KILLED, CLD_STOPPED as CLD_STOPPED, waitstatus_to_exitcode as waitstatus_to_exitcode + + if sys.platform == "linux": + from os import P_PIDFD as P_PIDFD if sys.version_info >= (3, 8): - from os import posix_spawn as posix_spawn, posix_spawnp as posix_spawnp + from os import ( + POSIX_SPAWN_CLOSE as POSIX_SPAWN_CLOSE, + POSIX_SPAWN_DUP2 as POSIX_SPAWN_DUP2, + POSIX_SPAWN_OPEN as POSIX_SPAWN_OPEN, + posix_spawn as posix_spawn, + posix_spawnp as posix_spawnp, + ) if sys.platform == "linux": from os import ( @@ -293,6 +307,16 @@ if sys.platform != "win32": if sys.version_info >= (3, 7): from os import register_at_fork as register_at_fork + if sys.platform != "darwin": + from os import ( + RWF_DSYNC as RWF_DSYNC, + RWF_HIPRI as RWF_HIPRI, + RWF_NOWAIT as RWF_NOWAIT, + RWF_SYNC as RWF_SYNC, + preadv as preadv, + pwritev as pwritev, + ) + # Not same as os.environ or os.environb # Because of this variable, we can't do "from posix import *" in os/__init__.pyi environ: dict[bytes, bytes] diff --git a/tests/stubtest_allowlists/darwin-py310.txt b/tests/stubtest_allowlists/darwin-py310.txt index dbe24dfe9..dc2d08fc3 100644 --- a/tests/stubtest_allowlists/darwin-py310.txt +++ b/tests/stubtest_allowlists/darwin-py310.txt @@ -5,15 +5,4 @@ curses.color_pair # Exists at runtime, but missing from stubs asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher -os.CLD_KILLED -os.CLD_STOPPED -os.POSIX_SPAWN_CLOSE -os.POSIX_SPAWN_DUP2 -os.POSIX_SPAWN_OPEN - mmap.MADV_FREE -posix.CLD_KILLED -posix.CLD_STOPPED -posix.POSIX_SPAWN_CLOSE -posix.POSIX_SPAWN_DUP2 -posix.POSIX_SPAWN_OPEN diff --git a/tests/stubtest_allowlists/darwin-py38.txt b/tests/stubtest_allowlists/darwin-py38.txt index bea495b9f..1b9e1e10e 100644 --- a/tests/stubtest_allowlists/darwin-py38.txt +++ b/tests/stubtest_allowlists/darwin-py38.txt @@ -1,11 +1,4 @@ _?curses.A_ITALIC # Exists at runtime, but missing from stubs -os.POSIX_SPAWN_CLOSE -os.POSIX_SPAWN_DUP2 -os.POSIX_SPAWN_OPEN - mmap.MADV_FREE -posix.POSIX_SPAWN_CLOSE -posix.POSIX_SPAWN_DUP2 -posix.POSIX_SPAWN_OPEN diff --git a/tests/stubtest_allowlists/darwin-py39.txt b/tests/stubtest_allowlists/darwin-py39.txt index 4cdab0315..84829dbb4 100644 --- a/tests/stubtest_allowlists/darwin-py39.txt +++ b/tests/stubtest_allowlists/darwin-py39.txt @@ -3,15 +3,4 @@ _?curses.A_ITALIC # Exists at runtime, but missing from stubs asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher -os.CLD_KILLED -os.CLD_STOPPED -os.POSIX_SPAWN_CLOSE -os.POSIX_SPAWN_DUP2 -os.POSIX_SPAWN_OPEN - mmap.MADV_FREE -posix.CLD_KILLED -posix.CLD_STOPPED -posix.POSIX_SPAWN_CLOSE -posix.POSIX_SPAWN_DUP2 -posix.POSIX_SPAWN_OPEN diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index 1b33628f7..afbf806e3 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -46,8 +46,6 @@ distutils.msvccompiler.MSVCCompiler.get_msvc_paths distutils.msvccompiler.MSVCCompiler.set_path_env_var distutils.msvccompiler.MacroExpander mimetypes.MimeTypes.read_windows_registry -os.ST_NOSUID -os.ST_RDONLY selectors.DefaultSelector.fileno socket.AddressInfo.AI_DEFAULT socket.AddressInfo.AI_MASK diff --git a/tests/stubtest_allowlists/linux-py310.txt b/tests/stubtest_allowlists/linux-py310.txt index ef8ca561a..dc131d830 100644 --- a/tests/stubtest_allowlists/linux-py310.txt +++ b/tests/stubtest_allowlists/linux-py310.txt @@ -21,20 +21,9 @@ select.epoll.register asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher mmap.MAP_POPULATE -os.CLD_KILLED -os.CLD_STOPPED os.EFD_CLOEXEC os.EFD_NONBLOCK os.EFD_SEMAPHORE -os.POSIX_SPAWN_CLOSE -os.POSIX_SPAWN_DUP2 -os.POSIX_SPAWN_OPEN -os.P_PIDFD -os.RWF_APPEND -os.RWF_DSYNC -os.RWF_HIPRI -os.RWF_NOWAIT -os.RWF_SYNC os.SPLICE_F_MORE os.SPLICE_F_MOVE os.SPLICE_F_NONBLOCK @@ -43,22 +32,13 @@ os.eventfd os.eventfd_read os.eventfd_write os.pidfd_open -os.preadv -os.pwritev os.splice -posix.CLD_KILLED -posix.CLD_STOPPED posix.EFD_[A-Z]+ -posix.P_PIDFD -posix.POSIX_SPAWN_[A-Z0-9]+ -posix.RWF_[A-Z]+ posix.SPLICE_[A-Z_]+ posix.copy_file_range posix.eventfd posix.eventfd_read posix.eventfd_write posix.pidfd_open -posix.preadv -posix.pwritev posix.splice time.pthread_getcpuclockid diff --git a/tests/stubtest_allowlists/linux-py37.txt b/tests/stubtest_allowlists/linux-py37.txt index 51840b518..65b1d3a20 100644 --- a/tests/stubtest_allowlists/linux-py37.txt +++ b/tests/stubtest_allowlists/linux-py37.txt @@ -3,13 +3,4 @@ ftplib.FTP.trust_server_pasv_ipv4_address # Dangerous to use, intentionally und pwd.getpwnam # Exists at runtime, but missing from stubs -os.RWF_DSYNC -os.RWF_HIPRI -os.RWF_NOWAIT -os.RWF_SYNC -os.preadv -os.pwritev -posix.RWF_[A-Z]+ -posix.preadv -posix.pwritev time.pthread_getcpuclockid diff --git a/tests/stubtest_allowlists/linux-py38.txt b/tests/stubtest_allowlists/linux-py38.txt index 0f060920c..1b2d122b2 100644 --- a/tests/stubtest_allowlists/linux-py38.txt +++ b/tests/stubtest_allowlists/linux-py38.txt @@ -1,19 +1,6 @@ select.epoll.register # Exists at runtime, but missing from stubs -os.POSIX_SPAWN_CLOSE -os.POSIX_SPAWN_DUP2 -os.POSIX_SPAWN_OPEN -os.RWF_DSYNC -os.RWF_HIPRI -os.RWF_NOWAIT -os.RWF_SYNC os.copy_file_range -os.preadv -os.pwritev -posix.POSIX_SPAWN_[A-Z0-9]+ -posix.RWF_[A-Z]+ posix.copy_file_range -posix.preadv -posix.pwritev time.pthread_getcpuclockid diff --git a/tests/stubtest_allowlists/linux-py39.txt b/tests/stubtest_allowlists/linux-py39.txt index 84e4dbcf1..dff92f9e8 100644 --- a/tests/stubtest_allowlists/linux-py39.txt +++ b/tests/stubtest_allowlists/linux-py39.txt @@ -4,27 +4,8 @@ select.epoll.register # Exists at runtime, but missing from stubs asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher -os.CLD_KILLED -os.CLD_STOPPED -os.POSIX_SPAWN_CLOSE -os.POSIX_SPAWN_DUP2 -os.POSIX_SPAWN_OPEN -os.P_PIDFD -os.RWF_DSYNC -os.RWF_HIPRI -os.RWF_NOWAIT -os.RWF_SYNC os.copy_file_range os.pidfd_open -os.preadv -os.pwritev -posix.CLD_KILLED -posix.CLD_STOPPED -posix.P_PIDFD -posix.POSIX_SPAWN_[A-Z0-9]+ -posix.RWF_[A-Z]+ posix.copy_file_range posix.pidfd_open -posix.preadv -posix.pwritev time.pthread_getcpuclockid