From 12a91ecbced9bd8d052f3f111b36c329ec97813c Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sat, 29 Nov 2025 21:45:28 +0400 Subject: [PATCH 1/5] [psutil] Complete common POSIX logic --- stubs/psutil/psutil/_psaix.pyi | 2 +- stubs/psutil/psutil/_psbsd.pyi | 2 +- stubs/psutil/psutil/_pslinux.pyi | 2 +- stubs/psutil/psutil/_psosx.pyi | 2 +- stubs/psutil/psutil/_psposix.pyi | 60 ++++++++++++++++++++++++--- stubs/psutil/psutil/_pssunos.pyi | 2 +- stubs/psutil/psutil/_psutil_aix.pyi | 2 +- stubs/psutil/psutil/_psutil_bsd.pyi | 4 +- stubs/psutil/psutil/_psutil_linux.pyi | 5 +-- stubs/psutil/psutil/_psutil_osx.pyi | 8 ++-- stubs/psutil/psutil/_psutil_sunos.pyi | 5 +-- 11 files changed, 70 insertions(+), 24 deletions(-) diff --git a/stubs/psutil/psutil/_psaix.pyi b/stubs/psutil/psutil/_psaix.pyi index b6632083c2f7..6f76c16eec03 100644 --- a/stubs/psutil/psutil/_psaix.pyi +++ b/stubs/psutil/psutil/_psaix.pyi @@ -108,5 +108,5 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw def open_files(self) -> list[_common.popenfile]: ... def num_fds(self) -> int: ... def num_ctx_switches(self) -> _common.pctxsw: ... - def wait(self, timeout: float | None = None): ... + def wait(self, timeout: float | None = None) -> int | None: ... def io_counters(self) -> _common.pio: ... diff --git a/stubs/psutil/psutil/_psbsd.pyi b/stubs/psutil/psutil/_psbsd.pyi index 58c26414d476..503f22f4f41b 100644 --- a/stubs/psutil/psutil/_psbsd.pyi +++ b/stubs/psutil/psutil/_psbsd.pyi @@ -177,7 +177,7 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw def num_ctx_switches(self) -> _common.pctxsw: ... def threads(self) -> list[_common.pthread]: ... def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... - def wait(self, timeout: float | None = None): ... + def wait(self, timeout: float | None = None) -> int | None: ... def nice_get(self) -> int: ... def nice_set(self, value: int) -> None: ... def status(self) -> str: ... diff --git a/stubs/psutil/psutil/_pslinux.pyi b/stubs/psutil/psutil/_pslinux.pyi index a0ca74631346..ff502d50db2a 100644 --- a/stubs/psutil/psutil/_pslinux.pyi +++ b/stubs/psutil/psutil/_pslinux.pyi @@ -260,7 +260,7 @@ if sys.platform == "linux": def io_counters(self) -> pio: ... def cpu_times(self) -> pcputimes: ... def cpu_num(self) -> int: ... - def wait(self, timeout: float | None = None): ... + def wait(self, timeout: float | None = None) -> int | None: ... def create_time(self, monotonic: bool = False) -> float: ... def memory_info(self) -> pmem: ... def memory_full_info(self) -> pfullmem: ... diff --git a/stubs/psutil/psutil/_psosx.pyi b/stubs/psutil/psutil/_psosx.pyi index cff4e93ea9b3..904629b6f556 100644 --- a/stubs/psutil/psutil/_psosx.pyi +++ b/stubs/psutil/psutil/_psosx.pyi @@ -110,7 +110,7 @@ if sys.platform == "darwin": def open_files(self) -> list[_common.popenfile]: ... def net_connections(self, kind: str = "inet"): ... def num_fds(self) -> int: ... - def wait(self, timeout: float | None = None): ... + def wait(self, timeout: float | None = None) -> int | None: ... def nice_get(self): ... def nice_set(self, value): ... def status(self) -> str: ... diff --git a/stubs/psutil/psutil/_psposix.pyi b/stubs/psutil/psutil/_psposix.pyi index 57b6ff163616..a4f047e47def 100644 --- a/stubs/psutil/psutil/_psposix.pyi +++ b/stubs/psutil/psutil/_psposix.pyi @@ -1,19 +1,67 @@ +import enum import sys -from _typeshed import FileDescriptorOrPath, StrOrBytesPath +from _typeshed import FileDescriptorOrPath, StrOrBytesPath, Unused +from collections.abc import Callable from ._common import sdiskusage def pid_exists(pid: int) -> bool: ... + +# Sync with `signal.Signals`, but with opposite values: +class Negsignal(enum.IntEnum): + SIGABRT = -6 + SIGFPE = -8 + SIGILL = -4 + SIGINT = -2 + SIGSEGV = -11 + SIGTERM = -15 + SIGALRM = -14 + SIGBUS = -7 + SIGCHLD = -17 + SIGCONT = -18 + SIGHUP = -1 + SIGIO = -29 + SIGIOT = 6 + SIGKILL = -9 + SIGPIPE = -13 + SIGPROF = -27 + SIGQUIT = -3 + SIGSTOP = -19 + SIGSYS = -31 + SIGTRAP = -5 + SIGTSTP = -20 + SIGTTIN = -21 + SIGTTOU = -22 + SIGURG = -23 + SIGUSR1 = -10 + SIGUSR2 = -12 + SIGVTALRM = -26 + SIGWINCH = -28 + SIGXCPU = -24 + SIGXFSZ = -25 + if sys.platform != "linux": + SIGEMT = -7 + SIGINFO = -29 + if sys.platform != "darwin": + SIGCLD = -17 + SIGPOLL = -29 + SIGPWR = -30 + SIGRTMAX = -64 + SIGRTMIN = -34 + if sys.version_info >= (3, 11): + SIGSTKFLT = -16 + +def negsig_to_enum(num: int) -> int: ... def wait_pid( pid: int, timeout: float | None = None, proc_name: str | None = None, - _waitpid=..., - _timer=..., + _waitpid: Unused = ..., + _timer: Callable[[], float] = ..., _min=..., - _sleep=..., - _pid_exists=..., -): ... + _sleep: Callable[[float], None] = ..., + _pid_exists: Callable[[int], bool] = ..., +) -> int | None: ... if sys.platform == "darwin": def disk_usage(path: StrOrBytesPath) -> sdiskusage: ... diff --git a/stubs/psutil/psutil/_pssunos.pyi b/stubs/psutil/psutil/_pssunos.pyi index 2676147f64bb..a29da96624fd 100644 --- a/stubs/psutil/psutil/_pssunos.pyi +++ b/stubs/psutil/psutil/_pssunos.pyi @@ -148,4 +148,4 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw def memory_maps(self) -> list[tuple[str, str, str, int, int, int]]: ... def num_fds(self) -> int: ... def num_ctx_switches(self) -> _common.pctxsw: ... - def wait(self, timeout: float | None = None): ... + def wait(self, timeout: float | None = None) -> int | None: ... diff --git a/stubs/psutil/psutil/_psutil_aix.pyi b/stubs/psutil/psutil/_psutil_aix.pyi index 9847329a318c..17977e3eadcb 100644 --- a/stubs/psutil/psutil/_psutil_aix.pyi +++ b/stubs/psutil/psutil/_psutil_aix.pyi @@ -7,7 +7,7 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw AF_LINK: Final = 18 def getpagesize() -> int: ... - def net_if_addrs(): ... + def net_if_addrs() -> list[tuple[str, int, str, str | None, str | None, str | None]]: ... def net_if_flags(nic_name: str, /) -> list[str]: ... def net_if_is_running(nic_name: str, /) -> bool: ... def net_if_mtu(nic_name: str, /) -> int: ... diff --git a/stubs/psutil/psutil/_psutil_bsd.pyi b/stubs/psutil/psutil/_psutil_bsd.pyi index 9a1ec2e746b1..964916a51f9b 100644 --- a/stubs/psutil/psutil/_psutil_bsd.pyi +++ b/stubs/psutil/psutil/_psutil_bsd.pyi @@ -23,13 +23,13 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw RLIM_INFINITY: Final[int] # only FreeBSD def getpagesize() -> int: ... - def net_if_addrs(): ... + def net_if_addrs() -> list[tuple[str, int, str, str | None, str | None, str | None]]: ... def net_if_flags(nic_name: str, /) -> list[str]: ... def net_if_is_running(nic_name: str, /) -> bool: ... def net_if_mtu(nic_name: str, /) -> int: ... def proc_priority_get(pid: int, /) -> int: ... def proc_priority_set(pid: int, priority: int, /) -> None: ... - def net_if_duplex_speed(nic_name: str, /): ... + def net_if_duplex_speed(nic_name: str, /) -> tuple[int, int]: ... # It's actually list of 2 elements def proc_is_zombie(pid: int, /) -> bool: ... version: Final[int] diff --git a/stubs/psutil/psutil/_psutil_linux.pyi b/stubs/psutil/psutil/_psutil_linux.pyi index 9fb15b422834..c19799ddbe9f 100644 --- a/stubs/psutil/psutil/_psutil_linux.pyi +++ b/stubs/psutil/psutil/_psutil_linux.pyi @@ -1,7 +1,6 @@ import sys if sys.platform == "linux": - from _typeshed import Incomplete from collections.abc import Sequence from typing import Final @@ -24,13 +23,13 @@ if sys.platform == "linux": RLIM_INFINITY: Final[int] def getpagesize() -> int: ... - def net_if_addrs(): ... + def net_if_addrs() -> list[tuple[str, int, str, str | None, str | None, str | None]]: ... def net_if_flags(nic_name: str, /) -> list[str]: ... def net_if_is_running(nic_name: str, /) -> bool: ... def net_if_mtu(nic_name: str, /) -> int: ... def proc_priority_get(pid: int, /) -> int: ... def proc_priority_set(pid: int, priority: int, /) -> None: ... - def users() -> list[tuple[Incomplete, ...]]: ... + def users() -> list[tuple[str, str, str, float, int]]: ... version: Final[int] DUPLEX_FULL: Final[int] diff --git a/stubs/psutil/psutil/_psutil_osx.pyi b/stubs/psutil/psutil/_psutil_osx.pyi index e6bef26354da..94978383df21 100644 --- a/stubs/psutil/psutil/_psutil_osx.pyi +++ b/stubs/psutil/psutil/_psutil_osx.pyi @@ -1,7 +1,7 @@ import sys if sys.platform == "darwin": - from _typeshed import Incomplete, StrOrBytesPath + from _typeshed import StrOrBytesPath from collections.abc import Sequence from socket import AddressFamily, SocketKind from typing import Final, TypeVar @@ -11,14 +11,14 @@ if sys.platform == "darwin": AF_LINK: Final = 18 def getpagesize() -> int: ... - def net_if_addrs(): ... + def net_if_addrs() -> list[tuple[str, int, str, str | None, str | None, str | None]]: ... def net_if_flags(nic_name: str, /) -> list[str]: ... def net_if_is_running(nic_name: str, /) -> bool: ... def net_if_mtu(nic_name: str, /) -> int: ... def proc_priority_get(pid: int, /) -> int: ... def proc_priority_set(pid: int, priority: int, /) -> None: ... - def net_if_duplex_speed(nic_name: str, /): ... - def users() -> list[tuple[Incomplete, ...]]: ... + def net_if_duplex_speed(nic_name: str, /) -> tuple[int, int]: ... # It's actually list of 2 elements + def users() -> list[tuple[str, str, str, float, int]]: ... def proc_is_zombie(pid: int, /) -> bool: ... version: Final[int] diff --git a/stubs/psutil/psutil/_psutil_sunos.pyi b/stubs/psutil/psutil/_psutil_sunos.pyi index b98853632d27..fe56efa827ba 100644 --- a/stubs/psutil/psutil/_psutil_sunos.pyi +++ b/stubs/psutil/psutil/_psutil_sunos.pyi @@ -2,19 +2,18 @@ import sys # sys.platform.startswith(("sunos", "solaris")): if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darwin": - from _typeshed import Incomplete from typing import Final AF_LINK: Final[int] def getpagesize() -> int: ... - def net_if_addrs(): ... + def net_if_addrs() -> list[tuple[str, int, str, str | None, str | None, str | None]]: ... def net_if_flags(nic_name: str, /) -> list[str]: ... def net_if_is_running(nic_name: str, /) -> bool: ... def net_if_mtu(nic_name: str, /) -> int: ... def proc_priority_get(pid: int, /) -> int: ... def proc_priority_set(pid: int, priority: int, /) -> None: ... - def users() -> list[tuple[Incomplete, ...]]: ... + def users() -> list[tuple[str, str, str, float, int]]: ... version: Final[int] # They could be different between different versions of SunOS/Solaris: From 9c9ef15140e74b44f4992ab3705e30122a87a9d9 Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sat, 29 Nov 2025 21:53:47 +0400 Subject: [PATCH 2/5] add sys.platform check to _psposix --- stubs/psutil/psutil/_psposix.pyi | 132 ++++++++++++++++--------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/stubs/psutil/psutil/_psposix.pyi b/stubs/psutil/psutil/_psposix.pyi index a4f047e47def..a3d9ccc8c90d 100644 --- a/stubs/psutil/psutil/_psposix.pyi +++ b/stubs/psutil/psutil/_psposix.pyi @@ -1,74 +1,76 @@ -import enum import sys -from _typeshed import FileDescriptorOrPath, StrOrBytesPath, Unused -from collections.abc import Callable -from ._common import sdiskusage +if sys.platform != "win32": + import enum + from _typeshed import FileDescriptorOrPath, StrOrBytesPath, Unused + from collections.abc import Callable -def pid_exists(pid: int) -> bool: ... + from ._common import sdiskusage -# Sync with `signal.Signals`, but with opposite values: -class Negsignal(enum.IntEnum): - SIGABRT = -6 - SIGFPE = -8 - SIGILL = -4 - SIGINT = -2 - SIGSEGV = -11 - SIGTERM = -15 - SIGALRM = -14 - SIGBUS = -7 - SIGCHLD = -17 - SIGCONT = -18 - SIGHUP = -1 - SIGIO = -29 - SIGIOT = 6 - SIGKILL = -9 - SIGPIPE = -13 - SIGPROF = -27 - SIGQUIT = -3 - SIGSTOP = -19 - SIGSYS = -31 - SIGTRAP = -5 - SIGTSTP = -20 - SIGTTIN = -21 - SIGTTOU = -22 - SIGURG = -23 - SIGUSR1 = -10 - SIGUSR2 = -12 - SIGVTALRM = -26 - SIGWINCH = -28 - SIGXCPU = -24 - SIGXFSZ = -25 - if sys.platform != "linux": - SIGEMT = -7 - SIGINFO = -29 - if sys.platform != "darwin": - SIGCLD = -17 - SIGPOLL = -29 - SIGPWR = -30 - SIGRTMAX = -64 - SIGRTMIN = -34 - if sys.version_info >= (3, 11): - SIGSTKFLT = -16 + def pid_exists(pid: int) -> bool: ... -def negsig_to_enum(num: int) -> int: ... -def wait_pid( - pid: int, - timeout: float | None = None, - proc_name: str | None = None, - _waitpid: Unused = ..., - _timer: Callable[[], float] = ..., - _min=..., - _sleep: Callable[[float], None] = ..., - _pid_exists: Callable[[int], bool] = ..., -) -> int | None: ... + # Sync with `signal.Signals`, but with opposite values: + class Negsignal(enum.IntEnum): + SIGABRT = -6 + SIGFPE = -8 + SIGILL = -4 + SIGINT = -2 + SIGSEGV = -11 + SIGTERM = -15 + SIGALRM = -14 + SIGBUS = -7 + SIGCHLD = -17 + SIGCONT = -18 + SIGHUP = -1 + SIGIO = -29 + SIGIOT = 6 + SIGKILL = -9 + SIGPIPE = -13 + SIGPROF = -27 + SIGQUIT = -3 + SIGSTOP = -19 + SIGSYS = -31 + SIGTRAP = -5 + SIGTSTP = -20 + SIGTTIN = -21 + SIGTTOU = -22 + SIGURG = -23 + SIGUSR1 = -10 + SIGUSR2 = -12 + SIGVTALRM = -26 + SIGWINCH = -28 + SIGXCPU = -24 + SIGXFSZ = -25 + if sys.platform != "linux": + SIGEMT = -7 + SIGINFO = -29 + if sys.platform != "darwin": + SIGCLD = -17 + SIGPOLL = -29 + SIGPWR = -30 + SIGRTMAX = -64 + SIGRTMIN = -34 + if sys.version_info >= (3, 11): + SIGSTKFLT = -16 -if sys.platform == "darwin": - def disk_usage(path: StrOrBytesPath) -> sdiskusage: ... + def negsig_to_enum(num: int) -> int: ... + def wait_pid( + pid: int, + timeout: float | None = None, + proc_name: str | None = None, + _waitpid: Unused = ..., + _timer: Callable[[], float] = ..., + _min=..., + _sleep: Callable[[float], None] = ..., + _pid_exists: Callable[[int], bool] = ..., + ) -> int | None: ... -else: - def disk_usage(path: FileDescriptorOrPath) -> sdiskusage: ... + if sys.platform == "darwin": + def disk_usage(path: StrOrBytesPath) -> sdiskusage: ... -def get_terminal_map() -> dict[int, str]: ... + else: + def disk_usage(path: FileDescriptorOrPath) -> sdiskusage: ... -__all__ = ["pid_exists", "wait_pid", "disk_usage", "get_terminal_map"] + def get_terminal_map() -> dict[int, str]: ... + + __all__ = ["pid_exists", "wait_pid", "disk_usage", "get_terminal_map"] From 8c7adc068c14bb249b4eca271c1149505baaae0f Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sat, 29 Nov 2025 21:56:07 +0400 Subject: [PATCH 3/5] add callable for _min --- stubs/psutil/psutil/_psposix.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stubs/psutil/psutil/_psposix.pyi b/stubs/psutil/psutil/_psposix.pyi index a3d9ccc8c90d..4f5ccecda575 100644 --- a/stubs/psutil/psutil/_psposix.pyi +++ b/stubs/psutil/psutil/_psposix.pyi @@ -2,7 +2,7 @@ import sys if sys.platform != "win32": import enum - from _typeshed import FileDescriptorOrPath, StrOrBytesPath, Unused + from _typeshed import FileDescriptorOrPath, Incomplete, StrOrBytesPath, Unused from collections.abc import Callable from ._common import sdiskusage @@ -60,7 +60,7 @@ if sys.platform != "win32": proc_name: str | None = None, _waitpid: Unused = ..., _timer: Callable[[], float] = ..., - _min=..., + _min: Callable[..., Incomplete] = ..., _sleep: Callable[[float], None] = ..., _pid_exists: Callable[[int], bool] = ..., ) -> int | None: ... From 858daafb3c19d97e341cac14e90b6ce77561c8ca Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sat, 29 Nov 2025 22:01:40 +0400 Subject: [PATCH 4/5] Add _psposix to win allowlist --- stubs/psutil/@tests/stubtest_allowlist_win32.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/stubs/psutil/@tests/stubtest_allowlist_win32.txt b/stubs/psutil/@tests/stubtest_allowlist_win32.txt index 1e781db20233..4a1f0ebae210 100644 --- a/stubs/psutil/@tests/stubtest_allowlist_win32.txt +++ b/stubs/psutil/@tests/stubtest_allowlist_win32.txt @@ -2,3 +2,4 @@ psutil._psosx psutil._pslinux psutil._psutil_osx psutil._psutil_linux +psutil._psposix From 12a3b644d3d71797e05964920a0d41a5089b1a7a Mon Sep 17 00:00:00 2001 From: donBarbos Date: Sat, 29 Nov 2025 22:08:23 +0400 Subject: [PATCH 5/5] ok, don't ignore _posix in win --- .../@tests/stubtest_allowlist_win32.txt | 1 - stubs/psutil/psutil/_psposix.pyi | 68 ++++++++++--------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/stubs/psutil/@tests/stubtest_allowlist_win32.txt b/stubs/psutil/@tests/stubtest_allowlist_win32.txt index 4a1f0ebae210..1e781db20233 100644 --- a/stubs/psutil/@tests/stubtest_allowlist_win32.txt +++ b/stubs/psutil/@tests/stubtest_allowlist_win32.txt @@ -2,4 +2,3 @@ psutil._psosx psutil._pslinux psutil._psutil_osx psutil._psutil_linux -psutil._psposix diff --git a/stubs/psutil/psutil/_psposix.pyi b/stubs/psutil/psutil/_psposix.pyi index 4f5ccecda575..f3fc5bc9f01e 100644 --- a/stubs/psutil/psutil/_psposix.pyi +++ b/stubs/psutil/psutil/_psposix.pyi @@ -1,29 +1,33 @@ +import enum import sys +from _typeshed import FileDescriptorOrPath, Incomplete, StrOrBytesPath, Unused +from collections.abc import Callable -if sys.platform != "win32": - import enum - from _typeshed import FileDescriptorOrPath, Incomplete, StrOrBytesPath, Unused - from collections.abc import Callable +from ._common import sdiskusage - from ._common import sdiskusage +def pid_exists(pid: int) -> bool: ... - def pid_exists(pid: int) -> bool: ... +# Sync with `signal.Signals`, but with opposite values: +class Negsignal(enum.IntEnum): + SIGABRT = -6 + SIGFPE = -8 + SIGILL = -4 + SIGINT = -2 + SIGSEGV = -11 + SIGTERM = -15 - # Sync with `signal.Signals`, but with opposite values: - class Negsignal(enum.IntEnum): - SIGABRT = -6 - SIGFPE = -8 - SIGILL = -4 - SIGINT = -2 - SIGSEGV = -11 - SIGTERM = -15 + if sys.platform == "win32": + SIGBREAK = -21 + CTRL_C_EVENT = 0 + CTRL_BREAK_EVENT = -1 + else: SIGALRM = -14 SIGBUS = -7 SIGCHLD = -17 SIGCONT = -18 SIGHUP = -1 SIGIO = -29 - SIGIOT = 6 + SIGIOT = -6 SIGKILL = -9 SIGPIPE = -13 SIGPROF = -27 @@ -53,24 +57,24 @@ if sys.platform != "win32": if sys.version_info >= (3, 11): SIGSTKFLT = -16 - def negsig_to_enum(num: int) -> int: ... - def wait_pid( - pid: int, - timeout: float | None = None, - proc_name: str | None = None, - _waitpid: Unused = ..., - _timer: Callable[[], float] = ..., - _min: Callable[..., Incomplete] = ..., - _sleep: Callable[[float], None] = ..., - _pid_exists: Callable[[int], bool] = ..., - ) -> int | None: ... +def negsig_to_enum(num: int) -> int: ... +def wait_pid( + pid: int, + timeout: float | None = None, + proc_name: str | None = None, + _waitpid: Unused = ..., + _timer: Callable[[], float] = ..., + _min: Callable[..., Incomplete] = ..., + _sleep: Callable[[float], None] = ..., + _pid_exists: Callable[[int], bool] = ..., +) -> int | None: ... - if sys.platform == "darwin": - def disk_usage(path: StrOrBytesPath) -> sdiskusage: ... +if sys.platform == "darwin": + def disk_usage(path: StrOrBytesPath) -> sdiskusage: ... - else: - def disk_usage(path: FileDescriptorOrPath) -> sdiskusage: ... +else: + def disk_usage(path: FileDescriptorOrPath) -> sdiskusage: ... - def get_terminal_map() -> dict[int, str]: ... +def get_terminal_map() -> dict[int, str]: ... - __all__ = ["pid_exists", "wait_pid", "disk_usage", "get_terminal_map"] +__all__ = ["pid_exists", "wait_pid", "disk_usage", "get_terminal_map"]