diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 057ad4578..fc0af0d47 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -101,6 +101,8 @@ if sys.platform != "win32": CLD_TRAPPED: int CLD_CONTINUED: 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 SCHED_BATCH: int # some flavors of Unix SCHED_IDLE: int # some flavors of Unix @@ -119,6 +121,8 @@ if sys.platform != "win32": if sys.platform == "linux": RTLD_DEEPBIND: int + GRND_NONBLOCK: int + GRND_RANDOM: int SEEK_SET: int SEEK_CUR: int @@ -161,6 +165,24 @@ O_NOATIME: int # Gnu extension if in C library O_PATH: int # Gnu extension if in C library O_TMPFILE: int # Gnu extension if in C library O_LARGEFILE: int # Gnu extension if in C library +O_ACCMODE: int # TODO: when does this exist? + +if sys.platform != "win32" and sys.platform != "darwin": + # posix, but apparently missing on macos + ST_APPEND: int + ST_MANDLOCK: int + ST_NOATIME: int + 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 curdir: str pardir: str @@ -396,7 +418,6 @@ def strerror(__code: int) -> str: ... def umask(__mask: int) -> int: ... if sys.platform != "win32": - # Unix only def ctermid() -> str: ... def getegid() -> int: ... def geteuid() -> int: ... @@ -426,7 +447,13 @@ if sys.platform != "win32": def getsid(__pid: int) -> int: ... def setsid() -> None: ... def setuid(__uid: int) -> None: ... - from posix import uname_result + @final + class uname_result(NamedTuple): + sysname: str + nodename: str + release: str + version: str + machine: str def uname() -> uname_result: ... @overload @@ -812,14 +839,18 @@ if sys.platform == "win32": def startfile(path: StrOrBytesPath, operation: str | None = ...) -> None: ... else: - # Unix only def spawnlp(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: StrOrBytesPath) -> int: ... def spawnlpe(mode: int, file: StrOrBytesPath, arg0: StrOrBytesPath, *args: Any) -> int: ... # Imprecise signature def spawnvp(mode: int, file: StrOrBytesPath, args: _ExecVArgs) -> int: ... def spawnvpe(mode: int, file: StrOrBytesPath, args: _ExecVArgs, env: _ExecEnv) -> int: ... def wait() -> tuple[int, int]: ... # Unix only if sys.platform != "darwin": - from posix import waitid_result + class waitid_result(NamedTuple): + si_pid: int + si_uid: int + si_signo: int + si_status: int + si_code: int def waitid(idtype: int, ident: int, options: int) -> waitid_result: ... def wait3(options: int) -> tuple[int, int, Any]: ... def wait4(pid: int, options: int) -> tuple[int, int, Any]: ... @@ -832,10 +863,36 @@ else: def WSTOPSIG(status: int) -> int: ... def WTERMSIG(status: int) -> int: ... if sys.version_info >= (3, 8): - from posix import posix_spawn as posix_spawn, posix_spawnp as posix_spawnp + def posix_spawn( + path: StrOrBytesPath, + argv: _ExecVArgs, + env: _ExecEnv, + *, + file_actions: Sequence[Tuple[Any, ...]] | None = ..., + setpgroup: int | None = ..., + resetids: bool = ..., + setsid: bool = ..., + setsigmask: Iterable[int] = ..., + setsigdef: Iterable[int] = ..., + scheduler: tuple[Any, sched_param] | None = ..., + ) -> int: ... + def posix_spawnp( + path: StrOrBytesPath, + argv: _ExecVArgs, + env: _ExecEnv, + *, + file_actions: Sequence[Tuple[Any, ...]] | None = ..., + setpgroup: int | None = ..., + resetids: bool = ..., + setsid: bool = ..., + setsigmask: Iterable[int] = ..., + setsigdef: Iterable[int] = ..., + scheduler: tuple[Any, sched_param] | None = ..., + ) -> int: ... if sys.platform != "win32": - from posix import sched_param + class sched_param(NamedTuple): + sched_priority: int def sched_get_priority_min(policy: int) -> int: ... # some flavors of Unix def sched_get_priority_max(policy: int) -> int: ... # some flavors of Unix def sched_yield() -> None: ... # some flavors of Unix diff --git a/stdlib/posix.pyi b/stdlib/posix.pyi index 474ef0b27..08b55d10a 100644 --- a/stdlib/posix.pyi +++ b/stdlib/posix.pyi @@ -1,179 +1,120 @@ import sys -from _typeshed import StrOrBytesPath -from os import _ExecEnv, _ExecVArgs, stat_result as stat_result -from typing import Any, Iterable, NamedTuple, Sequence, Tuple -from typing_extensions import final if sys.platform != "win32": # Actually defined here, but defining in os allows sharing code with windows - from os import listdir as listdir, times_result as times_result - @final - class uname_result(NamedTuple): - sysname: str - nodename: str - release: str - version: str - machine: str - if sys.platform != "darwin": - class waitid_result(NamedTuple): - si_pid: int - si_uid: int - si_signo: int - si_status: int - si_code: int - class sched_param(NamedTuple): - sched_priority: int - CLD_CONTINUED: int - CLD_DUMPED: int - CLD_EXITED: int - CLD_TRAPPED: int - - EX_CANTCREAT: int - EX_CONFIG: int - EX_DATAERR: int - EX_IOERR: int - EX_NOHOST: int - EX_NOINPUT: int - EX_NOPERM: int - EX_NOTFOUND: int - EX_NOUSER: int - EX_OK: int - EX_OSERR: int - EX_OSFILE: int - EX_PROTOCOL: int - EX_SOFTWARE: int - EX_TEMPFAIL: int - EX_UNAVAILABLE: int - EX_USAGE: int - - F_OK: int - R_OK: int - W_OK: int - X_OK: int - - F_LOCK: int - F_TEST: int - F_TLOCK: int - F_ULOCK: int + from os import ( + CLD_CONTINUED as CLD_CONTINUED, + CLD_DUMPED as CLD_DUMPED, + CLD_EXITED as CLD_EXITED, + CLD_TRAPPED as CLD_TRAPPED, + EX_CANTCREAT as EX_CANTCREAT, + EX_CONFIG as EX_CONFIG, + EX_DATAERR as EX_DATAERR, + EX_IOERR as EX_IOERR, + EX_NOHOST as EX_NOHOST, + EX_NOINPUT as EX_NOINPUT, + EX_NOPERM as EX_NOPERM, + EX_NOTFOUND as EX_NOTFOUND, + EX_NOUSER as EX_NOUSER, + EX_OK as EX_OK, + EX_OSERR as EX_OSERR, + EX_OSFILE as EX_OSFILE, + EX_PROTOCOL as EX_PROTOCOL, + EX_SOFTWARE as EX_SOFTWARE, + EX_TEMPFAIL as EX_TEMPFAIL, + EX_UNAVAILABLE as EX_UNAVAILABLE, + EX_USAGE as EX_USAGE, + F_LOCK as F_LOCK, + F_OK as F_OK, + F_TEST as F_TEST, + F_TLOCK as F_TLOCK, + F_ULOCK as F_ULOCK, + O_APPEND as O_APPEND, + O_ASYNC as O_ASYNC, + O_CREAT as O_CREAT, + O_DIRECT as O_DIRECT, + O_DIRECTORY as O_DIRECTORY, + O_DSYNC as O_DSYNC, + O_EXCL as O_EXCL, + O_LARGEFILE as O_LARGEFILE, + O_NDELAY as O_NDELAY, + O_NOATIME as O_NOATIME, + O_NOCTTY as O_NOCTTY, + O_NOFOLLOW as O_NOFOLLOW, + O_NONBLOCK as O_NONBLOCK, + O_RDONLY as O_RDONLY, + O_RDWR as O_RDWR, + O_RSYNC as O_RSYNC, + O_SYNC as O_SYNC, + O_TRUNC as O_TRUNC, + O_WRONLY as O_WRONLY, + P_ALL as P_ALL, + P_PGID as P_PGID, + P_PID as P_PID, + PRIO_PGRP as PRIO_PGRP, + PRIO_PROCESS as PRIO_PROCESS, + PRIO_USER as PRIO_USER, + R_OK as R_OK, + RTLD_GLOBAL as RTLD_GLOBAL, + RTLD_LAZY as RTLD_LAZY, + RTLD_LOCAL as RTLD_LOCAL, + RTLD_NODELETE as RTLD_NODELETE, + RTLD_NOLOAD as RTLD_NOLOAD, + RTLD_NOW as RTLD_NOW, + SCHED_BATCH as SCHED_BATCH, + SCHED_FIFO as SCHED_FIFO, + SCHED_IDLE as SCHED_IDLE, + SCHED_OTHER as SCHED_OTHER, + SCHED_RESET_ON_FORK as SCHED_RESET_ON_FORK, + SCHED_RR as SCHED_RR, + SCHED_SPORADIC as SCHED_SPORADIC, + SEEK_DATA as SEEK_DATA, + SEEK_HOLE as SEEK_HOLE, + TMP_MAX as TMP_MAX, + W_OK as W_OK, + WCONTINUED as WCONTINUED, + WCOREDUMP as WCOREDUMP, + WEXITED as WEXITED, + WEXITSTATUS as WEXITSTATUS, + WIFCONTINUED as WIFCONTINUED, + WIFEXITED as WIFEXITED, + WIFSIGNALED as WIFSIGNALED, + WIFSTOPPED as WIFSTOPPED, + WNOHANG as WNOHANG, + WNOWAIT as WNOWAIT, + WSTOPPED as WSTOPPED, + WSTOPSIG as WSTOPSIG, + WTERMSIG as WTERMSIG, + WUNTRACED as WUNTRACED, + X_OK as X_OK, + listdir as listdir, + stat_result as stat_result, + times_result as times_result, + uname_result as uname_result, + ) if sys.platform == "linux": - GRND_NONBLOCK: int - GRND_RANDOM: int - NGROUPS_MAX: int - - O_APPEND: int - O_ACCMODE: int - O_ASYNC: int - O_CREAT: int - O_DIRECT: int - O_DIRECTORY: int - O_DSYNC: int - O_EXCL: int - O_LARGEFILE: int - O_NDELAY: int - O_NOATIME: int - O_NOCTTY: int - O_NOFOLLOW: int - O_NONBLOCK: int - O_RDONLY: int - O_RDWR: int - O_RSYNC: int - O_SYNC: int - O_TRUNC: int - O_WRONLY: int - + from os import ( + GRND_NONBLOCK as GRND_NONBLOCK, + GRND_RANDOM as GRND_RANDOM, + RTLD_DEEPBIND as RTLD_DEEPBIND, + XATTR_CREATE as XATTR_CREATE, + XATTR_REPLACE as XATTR_REPLACE, + XATTR_SIZE_MAX as XATTR_SIZE_MAX, + ) if sys.platform != "darwin": - POSIX_FADV_DONTNEED: int - POSIX_FADV_NOREUSE: int - POSIX_FADV_NORMAL: int - POSIX_FADV_RANDOM: int - POSIX_FADV_SEQUENTIAL: int - POSIX_FADV_WILLNEED: int - - PRIO_PGRP: int - PRIO_PROCESS: int - PRIO_USER: int - - P_ALL: int - P_PGID: int - P_PID: int - - if sys.platform == "linux": - RTLD_DEEPBIND: int - RTLD_GLOBAL: int - RTLD_LAZY: int - RTLD_LOCAL: int - RTLD_NODELETE: int - RTLD_NOLOAD: int - RTLD_NOW: int - - SCHED_FIFO: int - SCHED_OTHER: int - SCHED_RR: int - - if sys.platform == "linux": - SCHED_BATCH: int - SCHED_IDLE: int - if sys.platform != "darwin": - SCHED_RESET_ON_FORK: int - - SEEK_DATA: int - SEEK_HOLE: int - - ST_APPEND: int - ST_MANDLOCK: int - ST_NOATIME: int - ST_NODEV: int - ST_NODIRATIME: int - ST_NOEXEC: int - ST_NOSUID: int - ST_RDONLY: int - ST_RELATIME: int - ST_SYNCHRONOUS: int - ST_WRITE: int - - TMP_MAX: int - WCONTINUED: int - def WCOREDUMP(__status: int) -> bool: ... - def WEXITSTATUS(status: int) -> int: ... - def WIFCONTINUED(status: int) -> bool: ... - def WIFEXITED(status: int) -> bool: ... - def WIFSIGNALED(status: int) -> bool: ... - def WIFSTOPPED(status: int) -> bool: ... - WNOHANG: int - def WSTOPSIG(status: int) -> int: ... - def WTERMSIG(status: int) -> int: ... - WUNTRACED: int - - XATTR_CREATE: int - XATTR_REPLACE: int - XATTR_SIZE_MAX: int + from os import ( + POSIX_FADV_DONTNEED as POSIX_FADV_DONTNEED, + POSIX_FADV_NOREUSE as POSIX_FADV_NOREUSE, + POSIX_FADV_NORMAL as POSIX_FADV_NORMAL, + POSIX_FADV_RANDOM as POSIX_FADV_RANDOM, + POSIX_FADV_SEQUENTIAL as POSIX_FADV_SEQUENTIAL, + POSIX_FADV_WILLNEED as POSIX_FADV_WILLNEED, + ) if sys.version_info >= (3, 8): - def posix_spawn( - path: StrOrBytesPath, - argv: _ExecVArgs, - env: _ExecEnv, - *, - file_actions: Sequence[Tuple[Any, ...]] | None = ..., - setpgroup: int | None = ..., - resetids: bool = ..., - setsid: bool = ..., - setsigmask: Iterable[int] = ..., - setsigdef: Iterable[int] = ..., - scheduler: tuple[Any, sched_param] | None = ..., - ) -> int: ... - def posix_spawnp( - path: StrOrBytesPath, - argv: _ExecVArgs, - env: _ExecEnv, - *, - file_actions: Sequence[Tuple[Any, ...]] | None = ..., - setpgroup: int | None = ..., - resetids: bool = ..., - setsid: bool = ..., - setsigmask: Iterable[int] = ..., - setsigdef: Iterable[int] = ..., - scheduler: tuple[Any, sched_param] | None = ..., - ) -> int: ... + from os import posix_spawn as posix_spawn, posix_spawnp as posix_spawnp + + # 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.txt b/tests/stubtest_allowlists/darwin.txt index 43c03a7c8..4b8443f75 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -12,9 +12,8 @@ os.EX_NOTFOUND os.SF_MNOWAIT os.SF_NODISKIO os.SF_SYNC -posix.sched_param # system dependent. Unclear if macos has it. +os.sched_param # system dependent. Unclear if macos has it. posix.EX_NOTFOUND -posix.XATTR.* # Value seems to be in docs but not defined in github macos readline.append_history_file # not defined in macos select.KQ_FILTER_NETDEV # system dependent select.kqueue.__init__ # default C signature is wrong @@ -42,6 +41,7 @@ posix.[a-z]+_(param|result)._(asdict|make|replace) # Platform differences that cannot be captured by the type system fcntl.[A-Z0-9_]+ os.SCHED_[A-Z_]+ +posix.SCHED_[A-Z_]+ # Loadable SQLite extensions are disabled on GitHub runners (sqlite3(.dbapi2)?.Connection.enable_load_extension)? diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index 36fcfe49b..a3442e8b5 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -45,6 +45,7 @@ posix.[a-z]+_(param|result)._(asdict|make|replace) # Platform differences that cannot be captured by the type system fcntl.[A-Z0-9_]+ os.SCHED_[A-Z_]+ +posix.SCHED_[A-Z_]+ # Loadable SQLite extensions are disabled on GitHub runners (sqlite3(.dbapi2)?.Connection.enable_load_extension)?