From e4edcf23e0e57ef1d7b28420af357378a91261a9 Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 8 Oct 2023 00:05:20 +0200 Subject: [PATCH] Fix platform availability of some Unix constants (#10857) --- stdlib/_curses.pyi | 3 ++- stdlib/os/__init__.pyi | 17 ++++++++++++++--- stdlib/select.pyi | 1 - stdlib/signal.pyi | 10 ++++++---- tests/stubtest_allowlists/darwin.txt | 5 ----- tests/stubtest_allowlists/linux.txt | 6 ------ 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index e2319a5fc..3604f7abe 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -61,7 +61,8 @@ if sys.platform != "win32": A_DIM: int A_HORIZONTAL: int A_INVIS: int - A_ITALIC: int + if sys.platform != "darwin": + A_ITALIC: int A_LEFT: int A_LOW: int A_NORMAL: int diff --git a/stdlib/os/__init__.pyi b/stdlib/os/__init__.pyi index 27e951e9f..7fd04218f 100644 --- a/stdlib/os/__init__.pyi +++ b/stdlib/os/__init__.pyi @@ -70,9 +70,20 @@ if sys.platform != "win32": POSIX_FADV_WILLNEED: int POSIX_FADV_DONTNEED: int - SF_NODISKIO: int - SF_MNOWAIT: int - SF_SYNC: int + if sys.platform != "linux" and sys.platform != "darwin": + # In the os-module docs, these are marked as being available + # on "Unix, not Emscripten, not WASI." + # However, in the source code, a comment indicates they're "FreeBSD constants". + # sys.platform could have one of many values on a FreeBSD Python build, + # so the sys-module docs recommend doing `if sys.platform.startswith('freebsd')` + # to detect FreeBSD builds. Unfortunately that would be too dynamic + # for type checkers, however. + SF_NODISKIO: int + SF_MNOWAIT: int + SF_SYNC: int + + if sys.version_info >= (3, 11): + SF_NOCACHE: int if sys.platform == "linux": XATTR_SIZE_MAX: int diff --git a/stdlib/select.pyi b/stdlib/select.pyi index 99b66126a..5e2828e42 100644 --- a/stdlib/select.pyi +++ b/stdlib/select.pyi @@ -137,7 +137,6 @@ if sys.platform == "linux": EPOLLRDNORM: int EPOLLWRBAND: int EPOLLWRNORM: int - EPOLL_RDHUP: int EPOLL_CLOEXEC: int if sys.platform != "linux" and sys.platform != "darwin" and sys.platform != "win32": diff --git a/stdlib/signal.pyi b/stdlib/signal.pyi index b0d1e4417..906a6dabe 100644 --- a/stdlib/signal.pyi +++ b/stdlib/signal.pyi @@ -21,8 +21,6 @@ class Signals(IntEnum): CTRL_C_EVENT: int CTRL_BREAK_EVENT: int else: - SIGEMT: int - SIGINFO: int SIGALRM: int SIGBUS: int SIGCHLD: int @@ -47,6 +45,9 @@ class Signals(IntEnum): SIGWINCH: int SIGXCPU: int SIGXFSZ: int + if sys.platform != "linux": + SIGEMT: int + SIGINFO: int if sys.platform != "darwin": SIGCLD: int SIGPOLL: int @@ -88,8 +89,9 @@ if sys.platform == "win32": CTRL_C_EVENT: Signals CTRL_BREAK_EVENT: Signals else: - SIGINFO: Signals - SIGEMT: Signals + if sys.platform != "linux": + SIGINFO: Signals + SIGEMT: Signals SIGALRM: Signals SIGBUS: Signals SIGCHLD: Signals diff --git a/tests/stubtest_allowlists/darwin.txt b/tests/stubtest_allowlists/darwin.txt index d0e3176c6..8e6610488 100644 --- a/tests/stubtest_allowlists/darwin.txt +++ b/tests/stubtest_allowlists/darwin.txt @@ -1,9 +1,4 @@ -_?curses.A_ITALIC - _posixsubprocess.cloexec_pipe -os.SF_MNOWAIT -os.SF_NODISKIO -os.SF_SYNC (os|posix).sched_param # system dependent. Unclear if macos has it. select.KQ_FILTER_NETDEV # system dependent select.kqueue.__init__ # default C signature is wrong diff --git a/tests/stubtest_allowlists/linux.txt b/tests/stubtest_allowlists/linux.txt index 97a4f867c..f2386ae01 100644 --- a/tests/stubtest_allowlists/linux.txt +++ b/tests/stubtest_allowlists/linux.txt @@ -1,13 +1,7 @@ _socket.* _posixsubprocess.cloexec_pipe -os.SF_MNOWAIT -os.SF_NODISKIO -os.SF_SYNC os.plock -select.EPOLL_RDHUP selectors.KqueueSelector -signal.SIGEMT -signal.SIGINFO socket.[A-Z0-9_]+ # Exists at runtime, but missing from stubs