diff --git a/stubs/gevent/METADATA.toml b/stubs/gevent/METADATA.toml index b4c7ee9cf896..58869c1ac94e 100644 --- a/stubs/gevent/METADATA.toml +++ b/stubs/gevent/METADATA.toml @@ -1,6 +1,6 @@ version = "25.9.*" upstream_repository = "https://github.com/gevent/gevent" -requires = ["types-greenlet", "types-psutil"] +requires = ["types-greenlet", "types-psutil>=7.2.0"] [tool.stubtest] # Run stubtest on all platforms, since there is some platform specific stuff diff --git a/stubs/gevent/gevent/events.pyi b/stubs/gevent/gevent/events.pyi index ffc491711f26..237d84ba2898 100644 --- a/stubs/gevent/gevent/events.pyi +++ b/stubs/gevent/gevent/events.pyi @@ -1,4 +1,3 @@ -import sys from collections.abc import Callable, Mapping, Sequence from types import ModuleType from typing import Any, Protocol, TypeVar, type_check_only @@ -6,6 +5,7 @@ from typing_extensions import TypeAlias from gevent.hub import Hub from greenlet import greenlet as greenlet_t +from psutil._ntuples import pmem _T = TypeVar("_T") # FIXME: While it would be nice to import Interface from zope.interface here so the @@ -17,17 +17,6 @@ Interface: TypeAlias = Any def implementer(interface: Interface, /) -> Callable[[_T], _T]: ... -# this is copied from types-psutil, it would be nice if we could just import this -# but it doesn't seem like we can... -if sys.platform == "linux": - from psutil._pslinux import pmem -elif sys.platform == "darwin": - from psutil._psosx import pmem -elif sys.platform == "win32": - from psutil._pswindows import pmem -else: - class pmem(Any): ... - subscribers: list[Callable[[Any], object]] @type_check_only diff --git a/stubs/psutil/@tests/stubtest_allowlist.txt b/stubs/psutil/@tests/stubtest_allowlist.txt index 049382cd3acd..82909808ec44 100644 --- a/stubs/psutil/@tests/stubtest_allowlist.txt +++ b/stubs/psutil/@tests/stubtest_allowlist.txt @@ -9,8 +9,5 @@ psutil._psutil_aix psutil._psutil_bsd psutil._psutil_sunos -# Test utilities -psutil.tests.* - # process_iter is enhanced with cache_clear method that's not detected by stubtest psutil.process_iter diff --git a/stubs/psutil/METADATA.toml b/stubs/psutil/METADATA.toml index bc7195f02d42..0f1e77640865 100644 --- a/stubs/psutil/METADATA.toml +++ b/stubs/psutil/METADATA.toml @@ -1,4 +1,4 @@ -version = "7.1.3" +version = "7.2.0" upstream_repository = "https://github.com/giampaolo/psutil" [tool.stubtest] diff --git a/stubs/psutil/psutil/__init__.pyi b/stubs/psutil/psutil/__init__.pyi index 91b21d8d2210..d9238ebf661c 100644 --- a/stubs/psutil/psutil/__init__.pyi +++ b/stubs/psutil/psutil/__init__.pyi @@ -52,29 +52,10 @@ from psutil._common import ( NoSuchProcess as NoSuchProcess, TimeoutExpired as TimeoutExpired, ZombieProcess as ZombieProcess, - pconn, - pcputimes, - pctxsw, - pgids, - pionice, - popenfile, - pthread, - puids, - sconn, - scpufreq, - scpustats, - sdiskio, - sdiskpart, - sdiskusage, - sfan, - shwtemp, - snetio, - snicaddr, - snicstats, - sswap, - suser, ) +from . import _ntuples as _ntp + if sys.platform == "linux": from ._pslinux import ( IOPRIO_CLASS_BE as IOPRIO_CLASS_BE, @@ -82,8 +63,8 @@ if sys.platform == "linux": IOPRIO_CLASS_NONE as IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT as IOPRIO_CLASS_RT, ) - def sensors_temperatures(fahrenheit: bool = ...) -> dict[str, list[shwtemp]]: ... - def sensors_fans() -> dict[str, list[sfan]]: ... + def sensors_temperatures(fahrenheit: bool = False) -> dict[str, list[_ntp.shwtemp]]: ... + def sensors_fans() -> dict[str, list[_ntp.sfan]]: ... PROCFS_PATH: str RLIMIT_AS: int RLIMIT_CORE: int @@ -121,28 +102,19 @@ if sys.platform == "win32": win_service_iter as win_service_iter, ) +# Linux + glibc, Windows, macOS, FreeBSD, NetBSD: +def heap_info() -> _ntp.pheap: ... +def heap_trim() -> None: ... + if sys.platform == "linux": - from ._pslinux import pfullmem, pmem, scputimes, sensors_battery as sensors_battery, svmem + from ._pslinux import sensors_battery as sensors_battery elif sys.platform == "darwin": - from ._psosx import pfullmem, pmem, scputimes, sensors_battery as sensors_battery, svmem + from ._psosx import sensors_battery as sensors_battery elif sys.platform == "win32": - from ._pswindows import pfullmem, pmem, scputimes, sensors_battery as sensors_battery, svmem + from ._pswindows import sensors_battery as sensors_battery else: - scputimes = Incomplete - - class pmem(Any): ... - class pfullmem(Any): ... - class svmem(Any): ... - def sensors_battery(): ... -if sys.platform == "linux": - from ._pslinux import pio -elif sys.platform == "win32": - from ._pswindows import pio -else: - from ._common import pio - AF_LINK: int version_info: tuple[int, int, int] __version__: str @@ -191,45 +163,45 @@ class Process: def cwd(self) -> str: ... def nice(self, value: int | None = None) -> int: ... if sys.platform != "win32": - def uids(self) -> puids: ... - def gids(self) -> pgids: ... + def uids(self) -> _ntp.puids: ... + def gids(self) -> _ntp.pgids: ... def terminal(self) -> str: ... def num_fds(self) -> int: ... if sys.platform != "darwin": - def io_counters(self) -> pio: ... - def ionice(self, ioclass: int | None = None, value: int | None = None) -> pionice: ... + def io_counters(self) -> _ntp.pio: ... + def ionice(self, ioclass: int | None = None, value: int | None = None) -> _ntp.pionice: ... @overload def cpu_affinity(self, cpus: None = None) -> list[int]: ... @overload def cpu_affinity(self, cpus: list[int]) -> None: ... def memory_maps(self, grouped: bool = True) -> list[Incomplete]: ... if sys.platform == "linux": - def rlimit(self, resource: int, limits: tuple[int, int] | None = ...) -> tuple[int, int]: ... + def rlimit(self, resource: int, limits: tuple[int, int] | None = None) -> tuple[int, int]: ... def cpu_num(self) -> int: ... def environ(self) -> dict[str, str]: ... if sys.platform == "win32": def num_handles(self) -> int: ... - def num_ctx_switches(self) -> pctxsw: ... + def num_ctx_switches(self) -> _ntp.pctxsw: ... def num_threads(self) -> int: ... - def threads(self) -> list[pthread]: ... + def threads(self) -> list[_ntp.pthread]: ... def children(self, recursive: bool = False) -> list[Process]: ... def cpu_percent(self, interval: float | None = None) -> float: ... - def cpu_times(self) -> pcputimes: ... - def memory_info(self) -> pmem: ... - def memory_full_info(self) -> pfullmem: ... + def cpu_times(self) -> _ntp.pcputimes: ... + def memory_info(self) -> _ntp.pmem: ... + def memory_full_info(self) -> _ntp.pfullmem: ... def memory_percent(self, memtype: str = "rss") -> float: ... - def open_files(self) -> list[popenfile]: ... + def open_files(self) -> list[_ntp.popenfile]: ... @deprecated('use "net_connections" method instead') - def connections(self, kind: str = "inet") -> list[pconn]: ... + def connections(self, kind: str = "inet") -> list[_ntp.pconn]: ... def send_signal(self, sig: int) -> None: ... def suspend(self) -> None: ... def resume(self) -> None: ... def terminate(self) -> None: ... def kill(self) -> None: ... def wait(self, timeout: float | None = None) -> int: ... - def net_connections(self, kind: str = "inet") -> list[pconn]: ... + def net_connections(self, kind: str = "inet") -> list[_ntp.pconn]: ... class Popen(Process): def __init__(self, *args, **kwargs) -> None: ... @@ -257,13 +229,13 @@ def wait_procs( ) -> tuple[list[Process], list[Process]]: ... def cpu_count(logical: bool = True) -> int | None: ... @overload -def cpu_freq(percpu: Literal[False] = False) -> scpufreq: ... +def cpu_freq(percpu: Literal[False] = False) -> _ntp.scpufreq: ... @overload -def cpu_freq(percpu: Literal[True]) -> list[scpufreq]: ... +def cpu_freq(percpu: Literal[True]) -> list[_ntp.scpufreq]: ... @overload -def cpu_times(percpu: Literal[False] = False) -> scputimes: ... +def cpu_times(percpu: Literal[False] = False) -> _ntp.scputimes: ... @overload -def cpu_times(percpu: Literal[True]) -> list[scputimes]: ... +def cpu_times(percpu: Literal[True]) -> list[_ntp.scputimes]: ... @overload def cpu_percent(interval: float | None = None, percpu: Literal[False] = False) -> float: ... @overload @@ -271,27 +243,29 @@ def cpu_percent(interval: float | None, percpu: Literal[True]) -> list[float]: . @overload def cpu_percent(*, percpu: Literal[True]) -> list[float]: ... @overload -def cpu_times_percent(interval: float | None = None, percpu: Literal[False] = False) -> scputimes: ... +def cpu_times_percent(interval: float | None = None, percpu: Literal[False] = False) -> _ntp.scputimes: ... @overload -def cpu_times_percent(interval: float | None, percpu: Literal[True]) -> list[scputimes]: ... +def cpu_times_percent(interval: float | None, percpu: Literal[True]) -> list[_ntp.scputimes]: ... @overload -def cpu_times_percent(*, percpu: Literal[True]) -> list[scputimes]: ... -def cpu_stats() -> scpustats: ... +def cpu_times_percent(*, percpu: Literal[True]) -> list[_ntp.scputimes]: ... +def cpu_stats() -> _ntp.scpustats: ... def getloadavg() -> tuple[float, float, float]: ... -def virtual_memory() -> svmem: ... -def swap_memory() -> sswap: ... -def disk_usage(path: str) -> sdiskusage: ... -def disk_partitions(all: bool = False) -> list[sdiskpart]: ... +def virtual_memory() -> _ntp.svmem: ... +def swap_memory() -> _ntp.sswap: ... +def disk_usage(path: str) -> _ntp.sdiskusage: ... +def disk_partitions(all: bool = False) -> list[_ntp.sdiskpart]: ... + +# TODO: Incorrect sdiskio for BSD systems: @overload -def disk_io_counters(perdisk: Literal[False] = False, nowrap: bool = True) -> sdiskio | None: ... +def disk_io_counters(perdisk: Literal[False] = False, nowrap: bool = True) -> _ntp.sdiskio | None: ... @overload -def disk_io_counters(perdisk: Literal[True], nowrap: bool = True) -> dict[str, sdiskio]: ... +def disk_io_counters(perdisk: Literal[True], nowrap: bool = True) -> dict[str, _ntp.sdiskio]: ... @overload -def net_io_counters(pernic: Literal[False] = False, nowrap: bool = True) -> snetio: ... +def net_io_counters(pernic: Literal[False] = False, nowrap: bool = True) -> _ntp.snetio: ... @overload -def net_io_counters(pernic: Literal[True], nowrap: bool = True) -> dict[str, snetio]: ... -def net_connections(kind: str = "inet") -> list[sconn]: ... -def net_if_addrs() -> dict[str, list[snicaddr]]: ... -def net_if_stats() -> dict[str, snicstats]: ... +def net_io_counters(pernic: Literal[True], nowrap: bool = True) -> dict[str, _ntp.snetio]: ... +def net_connections(kind: str = "inet") -> list[_ntp.sconn]: ... +def net_if_addrs() -> dict[str, list[_ntp.snicaddr]]: ... +def net_if_stats() -> dict[str, _ntp.snicstats]: ... def boot_time() -> float: ... -def users() -> list[suser]: ... +def users() -> list[_ntp.suser]: ... diff --git a/stubs/psutil/psutil/_common.pyi b/stubs/psutil/psutil/_common.pyi index c71c87f0aba7..8f952d28bdd4 100644 --- a/stubs/psutil/psutil/_common.pyi +++ b/stubs/psutil/psutil/_common.pyi @@ -6,9 +6,11 @@ from _typeshed import ConvertibleToFloat, FileDescriptorOrPath, Incomplete, StrO from collections import defaultdict from collections.abc import Callable from socket import AF_INET6 as AF_INET6, AddressFamily, SocketKind -from typing import BinaryIO, Final, NamedTuple, SupportsIndex, TypeVar, overload +from typing import BinaryIO, Final, SupportsIndex, TypeVar, overload from typing_extensions import ParamSpec +from . import _ntuples as ntp + POSIX: Final[bool] WINDOWS: Final[bool] LINUX: Final[bool] @@ -68,151 +70,6 @@ POWER_TIME_UNLIMITED: Final = BatteryTime.POWER_TIME_UNLIMITED ENCODING: Final[str] ENCODING_ERRS: Final[str] -class sswap(NamedTuple): - total: int - used: int - free: int - percent: float - sin: int - sout: int - -class sdiskusage(NamedTuple): - total: int - used: int - free: int - percent: float - -class sdiskio(NamedTuple): - read_count: int - write_count: int - read_bytes: int - write_bytes: int - read_time: int - write_time: int - -class sdiskpart(NamedTuple): - device: str - mountpoint: str - fstype: str - opts: str - -class snetio(NamedTuple): - bytes_sent: int - bytes_recv: int - packets_sent: int - packets_recv: int - errin: int - errout: int - dropin: int - dropout: int - -class suser(NamedTuple): - name: str - terminal: str | None - host: str | None - started: float - pid: str - -class sconn(NamedTuple): - fd: int - family: AddressFamily - type: SocketKind - laddr: addr | tuple[()] - raddr: addr | tuple[()] - status: str - pid: int | None - -class snicaddr(NamedTuple): - family: AddressFamily - address: str - netmask: str | None - broadcast: str | None - ptp: str | None - -class snicstats(NamedTuple): - isup: bool - duplex: int - speed: int - mtu: int - flags: str - -class scpustats(NamedTuple): - ctx_switches: int - interrupts: int - soft_interrupts: int - syscalls: int - -class scpufreq(NamedTuple): - current: float - min: float - max: float - -class shwtemp(NamedTuple): - label: str - current: float - high: float | None - critical: float | None - -class sbattery(NamedTuple): - percent: int - secsleft: int - power_plugged: bool - -class sfan(NamedTuple): - label: str - current: int - -class pcputimes(NamedTuple): - user: float - system: float - children_user: float - children_system: float - -class popenfile(NamedTuple): - path: str - fd: int - -class pthread(NamedTuple): - id: int - user_time: float - system_time: float - -class puids(NamedTuple): - real: int - effective: int - saved: int - -class pgids(NamedTuple): - real: int - effective: int - saved: int - -class pio(NamedTuple): - read_count: int - write_count: int - read_bytes: int - write_bytes: int - -class pionice(NamedTuple): - ioclass: int - value: int - -class pctxsw(NamedTuple): - voluntary: int - involuntary: int - -class pconn(NamedTuple): - fd: int - family: AddressFamily - type: SocketKind - laddr: addr - raddr: addr - status: str - -class addr(NamedTuple): - ip: str - port: int - conn_tmap: dict[str, tuple[list[AddressFamily], list[SocketKind]]] class Error(Exception): ... @@ -262,23 +119,23 @@ def conn_to_ntuple( fd: int, fam: int, type_: int, - laddr: addr | tuple[str, int] | tuple[()], - raddr: addr | tuple[str, int] | tuple[()], + laddr: ntp.addr | tuple[str, int] | tuple[()], + raddr: ntp.addr | tuple[str, int] | tuple[()], status: int | str, status_map: dict[int, str] | dict[str, str], pid: int, -) -> sconn: ... +) -> ntp.sconn: ... @overload def conn_to_ntuple( fd: int, fam: int, type_: int, - laddr: addr | tuple[str, int] | tuple[()], - raddr: addr | tuple[str, int] | tuple[()], + laddr: ntp.addr | tuple[str, int] | tuple[()], + raddr: ntp.addr | tuple[str, int] | tuple[()], status: int | str, status_map: dict[int, str] | dict[str, str], pid: None = None, -) -> pconn: ... +) -> ntp.pconn: ... def deprecated_method(replacement: str) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ... class _WrapNumbers: @@ -366,26 +223,6 @@ __all__ = [ "ENCODING", "ENCODING_ERRS", "AF_INET6", - # named tuples - "pconn", - "pcputimes", - "pctxsw", - "pgids", - "pio", - "pionice", - "popenfile", - "pthread", - "puids", - "sconn", - "scpustats", - "sdiskio", - "sdiskpart", - "sdiskusage", - "snetio", - "snicaddr", - "snicstats", - "sswap", - "suser", # utility functions "conn_tmap", "deprecated_method", diff --git a/stubs/psutil/psutil/_ntuples.pyi b/stubs/psutil/psutil/_ntuples.pyi new file mode 100644 index 000000000000..b61b6ac2db36 --- /dev/null +++ b/stubs/psutil/psutil/_ntuples.pyi @@ -0,0 +1,384 @@ +import sys +from _typeshed import Incomplete +from socket import AddressFamily, SocketKind +from typing import Any, NamedTuple + +# All named tuples are defined in this file, but due to the inability to detect some platforms, +# it was decided to store the correct named tuples inside platform-specific files. + +class sswap(NamedTuple): + total: int + used: int + free: int + percent: float + sin: int + sout: int + +class sdiskusage(NamedTuple): + total: int + used: int + free: int + percent: float + +# redefine for linux: +if sys.platform != "linux": + class sdiskio(NamedTuple): + read_count: int + write_count: int + read_bytes: int + write_bytes: int + read_time: int + write_time: int + +class sdiskpart(NamedTuple): + device: str + mountpoint: str + fstype: str + opts: str + +class snetio(NamedTuple): + bytes_sent: int + bytes_recv: int + packets_sent: int + packets_recv: int + errin: int + errout: int + dropin: int + dropout: int + +class suser(NamedTuple): + name: str + terminal: str | None + host: str | None + started: float + pid: str + +class sconn(NamedTuple): + fd: int + family: AddressFamily + type: SocketKind + laddr: addr | tuple[()] + raddr: addr | tuple[()] + status: str + pid: int | None + +class snicaddr(NamedTuple): + family: AddressFamily + address: str + netmask: str | None + broadcast: str | None + ptp: str | None + +class snicstats(NamedTuple): + isup: bool + duplex: int + speed: int + mtu: int + flags: str + +class scpustats(NamedTuple): + ctx_switches: int + interrupts: int + soft_interrupts: int + syscalls: int + +class scpufreq(NamedTuple): + current: float + min: float + max: float + +class shwtemp(NamedTuple): + label: str + current: float + high: float | None + critical: float | None + +class sbattery(NamedTuple): + percent: int + secsleft: int + power_plugged: bool + +class sfan(NamedTuple): + label: str + current: int + +if sys.platform == "win32": + class pheap(NamedTuple): + heap_used: Incomplete + mmap_used: Incomplete + heap_count: Incomplete + +else: + # if LINUX or MACOS or BSD: + class pheap(NamedTuple): + heap_used: Incomplete + mmap_used: Incomplete + +# redefine for linux: +if sys.platform != "linux": + class pcputimes(NamedTuple): + user: float + system: float + children_user: float + children_system: float + + class popenfile(NamedTuple): + path: str + fd: int + +class pthread(NamedTuple): + id: int + user_time: float + system_time: float + +class puids(NamedTuple): + real: int + effective: int + saved: int + +class pgids(NamedTuple): + real: int + effective: int + saved: int + +# redefine for linux and windows: +if sys.platform != "linux" and sys.platform != "win32": + class pio(NamedTuple): + read_count: int + write_count: int + read_bytes: int + write_bytes: int + +class pionice(NamedTuple): + ioclass: int + value: int + +class pctxsw(NamedTuple): + voluntary: int + involuntary: int + +class pconn(NamedTuple): + fd: int + family: AddressFamily + type: SocketKind + laddr: addr + raddr: addr + status: str + +class addr(NamedTuple): + ip: str + port: int + +if sys.platform == "linux": + class scputimes(NamedTuple): + # Note: scputimes has different fields depending on exactly how Linux + # is setup, but we'll include the "complete" set of fields + user: float + nice: float + system: float + idle: float + iowait: float + irq: float + softirq: float + steal: float + guest: float + guest_nice: float + + class svmem(NamedTuple): + total: int + available: int + percent: float + used: int + free: int + active: int + inactive: int + buffers: int + cached: int + shared: int + slab: int + + class sdiskio(NamedTuple): + read_count: int + write_count: int + read_bytes: int + write_bytes: int + read_time: int + write_time: int + read_merged_count: int + write_merged_count: int + busy_time: int + + class popenfile(NamedTuple): + path: str + fd: int + position: int + mode: str + flags: int + + class pmem(NamedTuple): + rss: int + vms: int + shared: int + text: int + lib: int + data: int + dirty: int + + class pfullmem(NamedTuple): + rss: int + vms: int + shared: int + text: int + lib: int + data: int + dirty: int + uss: int + pss: int + swap: int + + class pmmap_grouped(NamedTuple): + path: Incomplete + rss: Incomplete + size: Incomplete + pss: Incomplete + shared_clean: Incomplete + shared_dirty: Incomplete + private_clean: Incomplete + private_dirty: Incomplete + referenced: Incomplete + anonymous: Incomplete + swap: Incomplete + + class pmmap_ext(NamedTuple): + addr: Incomplete + perms: Incomplete + path: Incomplete + rss: Incomplete + size: Incomplete + pss: Incomplete + shared_clean: Incomplete + shared_dirty: Incomplete + private_clean: Incomplete + private_dirty: Incomplete + referenced: Incomplete + anonymous: Incomplete + swap: Incomplete + + class pio(NamedTuple): + read_count: int + write_count: int + read_bytes: int + write_bytes: int + read_chars: int + write_chars: int + + class pcputimes(NamedTuple): + user: float + system: float + children_user: float + children_system: float + iowait: float + +elif sys.platform == "win32": + class scputimes(NamedTuple): + user: float + system: float + idle: float + interrupt: float + dpc: float + + class svmem(NamedTuple): + total: int + available: int + percent: float + used: int + free: int + + class pmem(NamedTuple): + rss: int + vms: int + num_page_faults: int + peak_wset: int + wset: int + peak_paged_pool: int + paged_pool: int + peak_nonpaged_pool: int + nonpaged_pool: int + pagefile: int + peak_pagefile: int + private: int + + class pfullmem(NamedTuple): + rss: int + vms: int + num_page_faults: int + peak_wset: int + wset: int + peak_paged_pool: int + paged_pool: int + peak_nonpaged_pool: int + nonpaged_pool: int + pagefile: int + peak_pagefile: int + private: int + uss: int + + class pmmap_grouped(NamedTuple): + path: Incomplete + rss: Incomplete + + class pmmap_ext(NamedTuple): + addr: Incomplete + perms: Incomplete + path: Incomplete + rss: Incomplete + + class pio(NamedTuple): + read_count: int + write_count: int + read_bytes: int + write_bytes: int + other_count: int + other_bytes: int + +elif sys.platform == "darwin": + class scputimes(NamedTuple): + user: float + nice: float + system: float + idle: float + + class svmem(NamedTuple): + total: int + available: int + percent: float + used: int + free: int + active: int + inactive: int + wired: int + + class pmem(NamedTuple): + rss: int + vms: int + pfaults: int + pageins: int + + class pfullmem(NamedTuple): + rss: int + vms: int + pfaults: int + pageins: int + uss: int + +else: + # See _psbsd.pyi, _pssunos.pyi or _psaix.pyi + # BSD: svmem, scputimes, pmem, pfullmem, pcputimes, pmmap_grouped, pmmap_ext, sdiskio + # SUNOS: scputimes, pcputimes, svmem, pmem, pfullmem, pmmap_grouped, pmmap_ext + # AIX: pmem, pfullmem, scputimes, svmem + + scputimes = Incomplete + + class pmem(Any): ... + class pfullmem(Any): ... + class svmem(Any): ... diff --git a/stubs/psutil/psutil/_psaix.pyi b/stubs/psutil/psutil/_psaix.pyi index 6f76c16eec03..aab5c6eb329b 100644 --- a/stubs/psutil/psutil/_psaix.pyi +++ b/stubs/psutil/psutil/_psaix.pyi @@ -19,7 +19,7 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw usage_percent as usage_percent, ) - from . import _common, _psposix, _psutil_aix + from . import _ntuples as ntp, _psposix, _psutil_aix __extra__all__: Final[list[str]] HAS_THREADS: Final[bool] @@ -54,28 +54,28 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw _R = TypeVar("_R") def virtual_memory() -> svmem: ... - def swap_memory() -> _common.sswap: ... + def swap_memory() -> ntp.sswap: ... def cpu_times() -> scputimes: ... def per_cpu_times() -> list[scputimes]: ... def cpu_count_logical() -> int | None: ... def cpu_count_cores() -> int | None: ... - def cpu_stats() -> _common.scpustats: ... + def cpu_stats() -> ntp.scpustats: ... disk_io_counters = _psutil_aix.disk_io_counters disk_usage = _psposix.disk_usage - def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ... + def disk_partitions(all: bool = False) -> list[ntp.sdiskpart]: ... net_if_addrs = _psutil_aix.net_if_addrs net_io_counters = _psutil_aix.net_io_counters @overload - def net_connections(kind: str, _pid: Literal[-1] = -1) -> list[_common.sconn]: ... + def net_connections(kind: str, _pid: Literal[-1] = -1) -> list[ntp.sconn]: ... @overload - def net_connections(kind: str, _pid: int = -1) -> list[_common.pconn]: ... - def net_if_stats() -> dict[str, _common.snicstats]: ... + def net_connections(kind: str, _pid: int = -1) -> list[ntp.pconn]: ... + def net_if_stats() -> dict[str, ntp.snicstats]: ... def boot_time() -> float: ... - def users() -> list[_common.suser]: ... + def users() -> list[ntp.suser]: ... def pids() -> list[int]: ... def pid_exists(pid: int | str) -> bool: ... def wrap_exceptions(fun: Callable[_P, _R]) -> Callable[_P, _R]: ... @@ -92,21 +92,21 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw def environ(self) -> dict[str, str]: ... def create_time(self) -> float: ... def num_threads(self) -> int: ... - def threads(self) -> list[_common.pthread]: ... - def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... + def threads(self) -> list[ntp.pthread]: ... + def net_connections(self, kind: str = "inet") -> list[ntp.pconn]: ... def nice_get(self) -> int: ... def nice_set(self, value: int) -> None: ... def ppid(self) -> int: ... - def uids(self) -> _common.puids: ... - def gids(self) -> _common.puids: ... - def cpu_times(self) -> _common.pcputimes: ... + def uids(self) -> ntp.puids: ... + def gids(self) -> ntp.puids: ... + def cpu_times(self) -> ntp.pcputimes: ... def terminal(self) -> str | None: ... def cwd(self) -> str: ... def memory_info(self) -> pmem: ... memory_full_info = memory_info def status(self) -> str: ... - def open_files(self) -> list[_common.popenfile]: ... + def open_files(self) -> list[ntp.popenfile]: ... def num_fds(self) -> int: ... - def num_ctx_switches(self) -> _common.pctxsw: ... + def num_ctx_switches(self) -> ntp.pctxsw: ... def wait(self, timeout: float | None = None) -> int | None: ... - def io_counters(self) -> _common.pio: ... + def io_counters(self) -> ntp.pio: ... diff --git a/stubs/psutil/psutil/_psbsd.pyi b/stubs/psutil/psutil/_psbsd.pyi index 503f22f4f41b..36297b70fc59 100644 --- a/stubs/psutil/psutil/_psbsd.pyi +++ b/stubs/psutil/psutil/_psbsd.pyi @@ -22,7 +22,7 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw usage_percent as usage_percent, ) - from . import _common, _psposix, _psutil_bsd + from . import _ntuples as ntp, _psposix, _psutil_bsd _P = ParamSpec("_P") _R = TypeVar("_R") @@ -96,26 +96,28 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw busy_time: Incomplete def virtual_memory() -> svmem: ... - def swap_memory() -> _common.sswap: ... + def swap_memory() -> ntp.sswap: ... + heap_info = _psutil_bsd.heap_info # only FreeBSD and NetBSD + heap_trim = _psutil_bsd.heap_trim # only FreeBSD and NetBSD def cpu_times() -> scputimes: ... def per_cpu_times() -> list[scputimes]: ... def cpu_count_logical() -> int | None: ... def cpu_count_cores() -> int | None: ... - def cpu_stats() -> _common.scpustats: ... - def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ... + def cpu_stats() -> ntp.scpustats: ... + def disk_partitions(all: bool = False) -> list[ntp.sdiskpart]: ... disk_usage = _psposix.disk_usage disk_io_counters = _psutil_bsd.disk_io_counters net_io_counters = _psutil_bsd.net_io_counters net_if_addrs = _psutil_bsd.net_if_addrs - def net_if_stats() -> dict[str, _common.snicstats]: ... - def net_connections(kind: str) -> list[_common.sconn]: ... - def sensors_battery() -> _common.sbattery | None: ... # only FreeBSD - def sensors_temperatures() -> defaultdict[str, list[_common.shwtemp]]: ... # only FreeBSD - def cpu_freq() -> list[_common.scpufreq]: ... # only FreeBSD and OpenBSD + def net_if_stats() -> dict[str, ntp.snicstats]: ... + def net_connections(kind: str) -> list[ntp.sconn]: ... + def sensors_battery() -> ntp.sbattery | None: ... # only FreeBSD + def sensors_temperatures() -> defaultdict[str, list[ntp.shwtemp]]: ... # only FreeBSD + def cpu_freq() -> list[ntp.scpufreq]: ... # only FreeBSD and OpenBSD def boot_time() -> float: ... - def users() -> list[_common.suser]: ... + def users() -> list[ntp.suser]: ... INIT_BOOT_TIME: Final[float] # only NetBSD @@ -166,22 +168,22 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw def environ(self) -> dict[str, str]: ... def terminal(self) -> str | None: ... def ppid(self) -> int: ... - def uids(self) -> _common.puids: ... - def gids(self) -> _common.pgids: ... - def cpu_times(self) -> _common.pcputimes: ... + def uids(self) -> ntp.puids: ... + def gids(self) -> ntp.pgids: ... + def cpu_times(self) -> ntp.pcputimes: ... def cpu_num(self) -> int: ... # only FreeBSD def memory_info(self) -> pmem: ... memory_full_info = memory_info def create_time(self, monotonic: bool = False) -> float: ... def num_threads(self) -> int: ... - def num_ctx_switches(self) -> _common.pctxsw: ... - def threads(self) -> list[_common.pthread]: ... - def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... + def num_ctx_switches(self) -> ntp.pctxsw: ... + def threads(self) -> list[ntp.pthread]: ... + def net_connections(self, kind: str = "inet") -> list[ntp.pconn]: ... 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: ... - def io_counters(self) -> _common.pio: ... + def io_counters(self) -> ntp.pio: ... def cwd(self) -> str: ... class nt_mmap_grouped(NamedTuple): @@ -200,7 +202,7 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw ref_count: Incomplete shadow_count: Incomplete - def open_files(self) -> list[_common.popenfile]: ... + def open_files(self) -> list[ntp.popenfile]: ... def num_fds(self) -> int: ... def cpu_affinity_get(self) -> list[int]: ... # only FreeBSD def cpu_affinity_set(self, cpus: list[int]) -> None: ... # only FreeBSD diff --git a/stubs/psutil/psutil/_pslinux.pyi b/stubs/psutil/psutil/_pslinux.pyi index ff502d50db2a..7d538282d8ef 100644 --- a/stubs/psutil/psutil/_pslinux.pyi +++ b/stubs/psutil/psutil/_pslinux.pyi @@ -3,10 +3,10 @@ import sys if sys.platform == "linux": import enum import re - from _typeshed import FileDescriptorOrPath, Incomplete + from _typeshed import FileDescriptorOrPath from collections import defaultdict from collections.abc import Callable, Generator, Sequence - from typing import Final, NamedTuple, TypeVar, overload + from typing import Final, TypeVar, overload from typing_extensions import ParamSpec from psutil._common import ( @@ -33,7 +33,7 @@ if sys.platform == "linux": usage_percent as usage_percent, ) - from . import _common, _psposix, _psutil_linux + from . import _ntuples as ntp, _psposix, _psutil_linux _P = ParamSpec("_P") _R = TypeVar("_R") @@ -69,129 +69,22 @@ if sys.platform == "linux": PROC_STATUSES: Final[dict[str, str]] TCP_STATUSES: Final[dict[str, str]] - class svmem(NamedTuple): - total: int - available: int - percent: float - used: int - free: int - active: int - inactive: int - buffers: int - cached: int - shared: int - slab: int - - class sdiskio(NamedTuple): - read_count: Incomplete - write_count: Incomplete - read_bytes: Incomplete - write_bytes: Incomplete - read_time: Incomplete - write_time: Incomplete - read_merged_count: Incomplete - write_merged_count: Incomplete - busy_time: Incomplete - - class popenfile(NamedTuple): - path: str - fd: int - position: int - mode: str - flags: int - - class pmem(NamedTuple): - rss: int - vms: int - shared: int - text: int - lib: int - data: int - dirty: int - - class pfullmem(NamedTuple): - rss: int - vms: int - shared: int - text: int - lib: int - data: int - dirty: int - uss: int - pss: int - swap: int - - class pmmap_grouped(NamedTuple): - path: Incomplete - rss: Incomplete - size: Incomplete - pss: Incomplete - shared_clean: Incomplete - shared_dirty: Incomplete - private_clean: Incomplete - private_dirty: Incomplete - referenced: Incomplete - anonymous: Incomplete - swap: Incomplete - - class pmmap_ext(NamedTuple): - addr: Incomplete - perms: Incomplete - path: Incomplete - rss: Incomplete - size: Incomplete - pss: Incomplete - shared_clean: Incomplete - shared_dirty: Incomplete - private_clean: Incomplete - private_dirty: Incomplete - referenced: Incomplete - anonymous: Incomplete - swap: Incomplete - - class pio(NamedTuple): - read_count: int - write_count: int - read_bytes: int - write_bytes: int - read_chars: int - write_chars: int - - class pcputimes(NamedTuple): - user: float - system: float - children_user: float - children_system: float - iowait: float - def readlink(path: str) -> str: ... def file_flags_to_mode(flags: int) -> str: ... def is_storage_device(name: str) -> bool: ... - def set_scputimes_ntuple(procfs_path: str) -> None: ... - - class scputimes(NamedTuple): - # Note: scputimes has different fields depending on exactly how Linux - # is setup, but we'll include the "complete" set of fields - user: float - nice: float - system: float - idle: float - iowait: float - irq: float - softirq: float - steal: float - guest: float - guest_nice: float - + def _scputimes_ntuple(procfs_path: str) -> type[ntp.scputimes]: ... + scputimes = ntp.scputimes def calculate_avail_vmem(mems: dict[bytes, int]) -> int: ... - def virtual_memory() -> svmem: ... - def swap_memory() -> _common.sswap: ... - def cpu_times() -> scputimes: ... - def per_cpu_times() -> list[scputimes]: ... + def virtual_memory() -> ntp.svmem: ... + def swap_memory() -> ntp.sswap: ... + heap_info = _psutil_linux.heap_info + heap_trim = _psutil_linux.heap_trim + def cpu_times() -> ntp.scputimes: ... + def per_cpu_times() -> list[ntp.scputimes]: ... def cpu_count_logical() -> int | None: ... def cpu_count_cores() -> int | None: ... - def cpu_stats() -> _common.scpustats: ... - def cpu_freq() -> list[_common.scpufreq]: ... + def cpu_stats() -> ntp.scpustats: ... + def cpu_freq() -> list[ntp.scpufreq]: ... net_if_addrs = _psutil_linux.net_if_addrs @@ -203,23 +96,23 @@ if sys.platform == "linux": def get_proc_inodes(self, pid: int) -> defaultdict[str, list[tuple[int, int]]]: ... def get_all_inodes(self) -> dict[str, list[tuple[int, int]]]: ... @staticmethod - def decode_address(addr: str, family: int) -> _common.addr | tuple[()]: ... + def decode_address(addr: str, family: int) -> ntp.addr | tuple[()]: ... @staticmethod def process_inet( file: str, family: int, type_: int, inodes: dict[str, list[tuple[int, int]]], filter_pid: int | None = None - ) -> Generator[tuple[int, int, int, _common.addr | tuple[()], _common.addr | tuple[()], str, int | None]]: ... + ) -> Generator[tuple[int, int, int, ntp.addr | tuple[()], ntp.addr | tuple[()], str, int | None]]: ... @staticmethod def process_unix( file: FileDescriptorOrPath, family: int, inodes: dict[str, list[tuple[int, int]]], filter_pid: int | None = None ) -> Generator[tuple[int, int, int, str, str, str, int | None]]: ... @overload - def retrieve(self, kind: str, pid: int) -> list[_common.pconn]: ... + def retrieve(self, kind: str, pid: int) -> list[ntp.pconn]: ... @overload - def retrieve(self, kind: str, pid: None = None) -> list[_common.sconn]: ... + def retrieve(self, kind: str, pid: None = None) -> list[ntp.sconn]: ... - def net_connections(kind: str = "inet") -> list[_common.sconn]: ... + def net_connections(kind: str = "inet") -> list[ntp.sconn]: ... def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ... - def net_if_stats() -> dict[str, _common.snicstats]: ... + def net_if_stats() -> dict[str, ntp.snicstats]: ... disk_usage = _psposix.disk_usage @@ -235,11 +128,11 @@ if sys.platform == "linux": def ask_sys_class_block(self) -> str | None: ... def find(self) -> str | None: ... - def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ... + def disk_partitions(all: bool = False) -> list[ntp.sdiskpart]: ... def sensors_temperatures() -> dict[str, list[tuple[str, float, float | None, float | None]]]: ... - def sensors_fans() -> dict[str, list[_common.sfan]]: ... - def sensors_battery() -> _common.sbattery | None: ... - def users() -> list[_common.suser]: ... + def sensors_fans() -> dict[str, list[ntp.sfan]]: ... + def sensors_battery() -> ntp.sbattery | None: ... + def users() -> list[ntp.suser]: ... def boot_time() -> float: ... def pids() -> list[int]: ... def pid_exists(pid: int) -> bool: ... @@ -257,32 +150,32 @@ if sys.platform == "linux": def cmdline(self) -> list[str]: ... def environ(self) -> dict[str, str]: ... def terminal(self) -> str | None: ... - def io_counters(self) -> pio: ... - def cpu_times(self) -> pcputimes: ... + def io_counters(self) -> ntp.pio: ... + def cpu_times(self) -> ntp.pcputimes: ... def cpu_num(self) -> int: ... 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: ... + def memory_info(self) -> ntp.pmem: ... + def memory_full_info(self) -> ntp.pfullmem: ... def memory_maps(self) -> list[tuple[str, str, str, int, int, int, int, int, int, int, int, int, int]]: ... def cwd(self) -> str: ... - def num_ctx_switches(self, _ctxsw_re: re.Pattern[bytes] = ...) -> _common.pctxsw: ... + def num_ctx_switches(self, _ctxsw_re: re.Pattern[bytes] = ...) -> ntp.pctxsw: ... def num_threads(self, _num_threads_re: re.Pattern[bytes] = ...) -> int: ... - def threads(self) -> list[_common.pthread]: ... + def threads(self) -> list[ntp.pthread]: ... def nice_get(self) -> int: ... def nice_set(self, value: int) -> None: ... def cpu_affinity_get(self) -> list[int]: ... def cpu_affinity_set(self, cpus: Sequence[int]) -> None: ... - def ionice_get(self) -> _common.pionice: ... + def ionice_get(self) -> ntp.pionice: ... def ionice_set(self, ioclass: int, value: int | None) -> None: ... @overload def rlimit(self, resource_: int, limits: tuple[int, int]) -> None: ... @overload def rlimit(self, resource_: int, limits: None = None) -> tuple[int, int]: ... def status(self) -> str: ... - def open_files(self) -> list[popenfile]: ... - def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... + def open_files(self) -> list[ntp.popenfile]: ... + def net_connections(self, kind: str = "inet") -> list[ntp.pconn]: ... def num_fds(self) -> int: ... def ppid(self) -> int: ... - def uids(self, _uids_re: re.Pattern[bytes] = ...) -> _common.puids: ... - def gids(self, _gids_re: re.Pattern[bytes] = ...) -> _common.pgids: ... + def uids(self, _uids_re: re.Pattern[bytes] = ...) -> ntp.puids: ... + def gids(self, _gids_re: re.Pattern[bytes] = ...) -> ntp.pgids: ... diff --git a/stubs/psutil/psutil/_psosx.pyi b/stubs/psutil/psutil/_psosx.pyi index 704ede6f5b6b..037940bd4963 100644 --- a/stubs/psutil/psutil/_psosx.pyi +++ b/stubs/psutil/psutil/_psosx.pyi @@ -2,7 +2,7 @@ import sys if sys.platform == "darwin": from collections.abc import Callable - from typing import Final, NamedTuple, TypeVar + from typing import Final, TypeVar from typing_extensions import ParamSpec from psutil._common import ( @@ -18,7 +18,7 @@ if sys.platform == "darwin": usage_percent as usage_percent, ) - from . import _common, _psposix, _psutil_osx + from . import _ntuples as ntp, _psposix, _psutil_osx _P = ParamSpec("_P") _R = TypeVar("_R") @@ -31,57 +31,30 @@ if sys.platform == "darwin": kinfo_proc_map: Final[dict[str, int]] pidtaskinfo_map: Final[dict[str, int]] - class scputimes(NamedTuple): - user: float - nice: float - system: float - idle: float - - class svmem(NamedTuple): - total: int - available: int - percent: float - used: int - free: int - active: int - inactive: int - wired: int - - class pmem(NamedTuple): - rss: int - vms: int - pfaults: int - pageins: int - - class pfullmem(NamedTuple): - rss: int - vms: int - pfaults: int - pageins: int - uss: int - - def virtual_memory() -> svmem: ... - def swap_memory() -> _common.sswap: ... - def cpu_times() -> scputimes: ... - def per_cpu_times() -> list[scputimes]: ... + def virtual_memory() -> ntp.svmem: ... + def swap_memory() -> ntp.sswap: ... + heap_info = _psutil_osx.heap_info + heap_trim = _psutil_osx.heap_trim + def cpu_times() -> ntp.scputimes: ... + def per_cpu_times() -> list[ntp.scputimes]: ... def cpu_count_logical() -> int | None: ... def cpu_count_cores() -> int | None: ... - def cpu_stats() -> _common.scpustats: ... - def cpu_freq() -> list[_common.scpufreq]: ... + def cpu_stats() -> ntp.scpustats: ... + def cpu_freq() -> list[ntp.scpufreq]: ... disk_usage = _psposix.disk_usage disk_io_counters = _psutil_osx.disk_io_counters - def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ... - def sensors_battery() -> _common.sbattery | None: ... + def disk_partitions(all: bool = False) -> list[ntp.sdiskpart]: ... + def sensors_battery() -> ntp.sbattery | None: ... net_io_counters = _psutil_osx.net_io_counters net_if_addrs = _psutil_osx.net_if_addrs - def net_connections(kind: str = "inet") -> list[_common.sconn]: ... - def net_if_stats() -> dict[str, _common.snicstats]: ... + def net_connections(kind: str = "inet") -> list[ntp.sconn]: ... + def net_if_stats() -> dict[str, ntp.snicstats]: ... def boot_time() -> float: ... INIT_BOOT_TIME: float def adjust_proc_create_time(ctime: float) -> float: ... - def users() -> list[_common.suser]: ... + def users() -> list[ntp.suser]: ... def pids() -> list[int]: ... pid_exists = _psposix.pid_exists def wrap_exceptions(fun: Callable[_P, _R]) -> Callable[_P, _R]: ... @@ -98,20 +71,20 @@ if sys.platform == "darwin": def environ(self) -> dict[str, str]: ... def ppid(self) -> int: ... def cwd(self) -> str: ... - def uids(self) -> _common.puids: ... - def gids(self) -> _common.puids: ... + def uids(self) -> ntp.puids: ... + def gids(self) -> ntp.puids: ... def terminal(self) -> str | None: ... - def memory_info(self) -> pmem: ... - def memory_full_info(self) -> pfullmem: ... - def cpu_times(self) -> _common.pcputimes: ... + def memory_info(self) -> ntp.pmem: ... + def memory_full_info(self) -> ntp.pfullmem: ... + def cpu_times(self) -> ntp.pcputimes: ... def create_time(self, monotonic: bool = False) -> float: ... - def num_ctx_switches(self) -> _common.pctxsw: ... + def num_ctx_switches(self) -> ntp.pctxsw: ... def num_threads(self) -> int: ... - def open_files(self) -> list[_common.popenfile]: ... - def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... + def open_files(self) -> list[ntp.popenfile]: ... + def net_connections(self, kind: str = "inet") -> list[ntp.pconn]: ... def num_fds(self) -> int: ... 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: ... - def threads(self) -> list[_common.pthread]: ... + def threads(self) -> list[ntp.pthread]: ... diff --git a/stubs/psutil/psutil/_psposix.pyi b/stubs/psutil/psutil/_psposix.pyi index f3fc5bc9f01e..8a9e73ca1824 100644 --- a/stubs/psutil/psutil/_psposix.pyi +++ b/stubs/psutil/psutil/_psposix.pyi @@ -3,7 +3,7 @@ import sys from _typeshed import FileDescriptorOrPath, Incomplete, StrOrBytesPath, Unused from collections.abc import Callable -from ._common import sdiskusage +from . import _ntuples as ntp def pid_exists(pid: int) -> bool: ... @@ -70,10 +70,10 @@ def wait_pid( ) -> int | None: ... if sys.platform == "darwin": - def disk_usage(path: StrOrBytesPath) -> sdiskusage: ... + def disk_usage(path: StrOrBytesPath) -> ntp.sdiskusage: ... else: - def disk_usage(path: FileDescriptorOrPath) -> sdiskusage: ... + def disk_usage(path: FileDescriptorOrPath) -> ntp.sdiskusage: ... def get_terminal_map() -> dict[int, str]: ... diff --git a/stubs/psutil/psutil/_pssunos.pyi b/stubs/psutil/psutil/_pssunos.pyi index a29da96624fd..f21ab5e6ba96 100644 --- a/stubs/psutil/psutil/_pssunos.pyi +++ b/stubs/psutil/psutil/_pssunos.pyi @@ -22,7 +22,7 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw usage_percent as usage_percent, ) - from . import _common, _psposix, _psutil_sunos + from . import _ntuples as ntp, _psposix, _psutil_sunos _P = ParamSpec("_P") _R = TypeVar("_R") @@ -77,28 +77,28 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw locked: Incomplete def virtual_memory() -> svmem: ... - def swap_memory() -> _common.sswap: ... + def swap_memory() -> ntp.sswap: ... def cpu_times() -> scputimes: ... def per_cpu_times() -> list[scputimes]: ... def cpu_count_logical() -> int | None: ... def cpu_count_cores() -> int | None: ... - def cpu_stats() -> _common.scpustats: ... + def cpu_stats() -> ntp.scpustats: ... disk_io_counters = _psutil_sunos.disk_io_counters disk_usage = _psposix.disk_usage - def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ... + def disk_partitions(all: bool = False) -> list[ntp.sdiskpart]: ... net_io_counters = _psutil_sunos.net_io_counters net_if_addrs = _psutil_sunos.net_if_addrs @overload - def net_connections(kind: str, _pid: Literal[-1] = -1) -> list[_common.sconn]: ... + def net_connections(kind: str, _pid: Literal[-1] = -1) -> list[ntp.sconn]: ... @overload - def net_connections(kind: str, _pid: int = -1) -> list[_common.pconn]: ... - def net_if_stats() -> dict[str, _common.snicstats]: ... + def net_connections(kind: str, _pid: int = -1) -> list[ntp.pconn]: ... + def net_if_stats() -> dict[str, ntp.snicstats]: ... def boot_time() -> float: ... - def users() -> list[_common.suser]: ... + def users() -> list[ntp.suser]: ... def pids() -> list[int]: ... def pid_exists(pid: int) -> bool: ... def wrap_exceptions(fun: Callable[_P, _R]) -> Callable[_P, _R]: ... @@ -118,18 +118,18 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw def nice_get(self) -> int: ... def nice_set(self, value: int) -> None: ... def ppid(self) -> int: ... - def uids(self) -> _common.puids: ... - def gids(self) -> _common.puids: ... - def cpu_times(self) -> _common.pcputimes: ... + def uids(self) -> ntp.puids: ... + def gids(self) -> ntp.puids: ... + def cpu_times(self) -> ntp.pcputimes: ... def cpu_num(self) -> int: ... def terminal(self) -> str | None: ... def cwd(self) -> str: ... def memory_info(self) -> pmem: ... memory_full_info = memory_info def status(self) -> str: ... - def threads(self) -> list[_common.pthread]: ... - def open_files(self) -> list[_common.popenfile]: ... - def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... + def threads(self) -> list[ntp.pthread]: ... + def open_files(self) -> list[ntp.popenfile]: ... + def net_connections(self, kind: str = "inet") -> list[ntp.pconn]: ... class nt_mmap_grouped(NamedTuple): path: Incomplete @@ -147,5 +147,5 @@ 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 num_ctx_switches(self) -> ntp.pctxsw: ... def wait(self, timeout: float | None = None) -> int | None: ... diff --git a/stubs/psutil/psutil/_psutil_bsd.pyi b/stubs/psutil/psutil/_psutil_bsd.pyi index 964916a51f9b..2d876cd2cf9f 100644 --- a/stubs/psutil/psutil/_psutil_bsd.pyi +++ b/stubs/psutil/psutil/_psutil_bsd.pyi @@ -126,6 +126,8 @@ if sys.platform != "linux" and sys.platform != "win32" and sys.platform != "darw def per_cpu_times() -> list[tuple[float, float, float, float, float]]: ... def pids() -> list[int]: ... def swap_mem() -> tuple[int, int, int, int, int]: ... + def heap_info() -> tuple[int, int]: ... # only FreeBSD and NetBSD + def heap_trim() -> None: ... # only FreeBSD and NetBSD def users() -> list[tuple[str, str, str, float, int | None]]: ... # returns None only in OpenBSD def virtual_mem() -> tuple[int, ...]: ... # tuple's length depends on OS @overload diff --git a/stubs/psutil/psutil/_psutil_linux.pyi b/stubs/psutil/psutil/_psutil_linux.pyi index c19799ddbe9f..d24279961311 100644 --- a/stubs/psutil/psutil/_psutil_linux.pyi +++ b/stubs/psutil/psutil/_psutil_linux.pyi @@ -42,6 +42,8 @@ if sys.platform == "linux": def proc_cpu_affinity_set(pid: int, cpu_set: Sequence[int], /) -> None: ... def disk_partitions(mtab_path: str, /) -> list[tuple[str, str, str, str]]: ... def net_if_duplex_speed(nic_name: str, /) -> tuple[int, int]: ... # It's actually list of 2 elements + def heap_info() -> tuple[int, int]: ... + def heap_trim() -> bool: ... def linux_sysinfo() -> tuple[int, int, int, int, int, int, int]: ... def check_pid_range(pid: int, /) -> None: ... def set_debug(value: bool, /) -> None: ... diff --git a/stubs/psutil/psutil/_psutil_osx.pyi b/stubs/psutil/psutil/_psutil_osx.pyi index 94978383df21..2ea2baca3d05 100644 --- a/stubs/psutil/psutil/_psutil_osx.pyi +++ b/stubs/psutil/psutil/_psutil_osx.pyi @@ -67,6 +67,8 @@ if sys.platform == "darwin": def disk_partitions() -> list[tuple[str, str, str, str]]: ... def disk_usage_used(mount_point: StrOrBytesPath, default: _T, /) -> int | _T: ... def has_cpu_freq() -> bool: ... + def heap_info() -> tuple[int, int]: ... + def heap_trim() -> None: ... def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ... def per_cpu_times() -> list[tuple[float, float, float, float]]: ... def pids() -> list[int]: ... diff --git a/stubs/psutil/psutil/_psutil_windows.pyi b/stubs/psutil/psutil/_psutil_windows.pyi index 74c6b1b5845f..f48ed77998b2 100644 --- a/stubs/psutil/psutil/_psutil_windows.pyi +++ b/stubs/psutil/psutil/_psutil_windows.pyi @@ -79,6 +79,8 @@ if sys.platform == "win32": def getpagesize() -> int: ... def swap_percent() -> float: ... def init_loadavg_counter() -> None: ... + def heap_info() -> tuple[int, int, int]: ... + def heap_trim() -> int: ... def net_connections( pid: int, af_filter: Sequence[AddressFamily | int | None], type_filter: Sequence[SocketKind | int | None], / ) -> list[tuple[int, int, int, tuple[str | None, int], tuple[str | None, int], int, int]]: ... diff --git a/stubs/psutil/psutil/_pswindows.pyi b/stubs/psutil/psutil/_pswindows.pyi index 72cb25418787..77e4728ddbd5 100644 --- a/stubs/psutil/psutil/_pswindows.pyi +++ b/stubs/psutil/psutil/_pswindows.pyi @@ -2,10 +2,9 @@ import sys if sys.platform == "win32": import enum - from _typeshed import Incomplete from collections.abc import Callable, Iterable, Iterator from signal import Signals - from typing import Final, Literal, NamedTuple, TypedDict, TypeVar, overload, type_check_only + from typing import Final, Literal, TypedDict, TypeVar, overload, type_check_only from typing_extensions import ParamSpec from psutil import _psutil_windows @@ -32,7 +31,7 @@ if sys.platform == "win32": REALTIME_PRIORITY_CLASS as REALTIME_PRIORITY_CLASS, ) - from . import _common + from . import _ntuples as ntp __extra__all__: Final[list[str]] CONN_DELETE_TCB: Final = "DELETE_TCB" @@ -67,96 +66,37 @@ if sys.platform == "win32": pinfo_map: Final[dict[str, int]] - class scputimes(NamedTuple): - user: float - system: float - idle: float - interrupt: float - dpc: float - - class svmem(NamedTuple): - total: int - available: int - percent: float - used: int - free: int - - class pmem(NamedTuple): - rss: int - vms: int - num_page_faults: int - peak_wset: int - wset: int - peak_paged_pool: int - paged_pool: int - peak_nonpaged_pool: int - nonpaged_pool: int - pagefile: int - peak_pagefile: int - private: int - - class pfullmem(NamedTuple): - rss: int - vms: int - num_page_faults: int - peak_wset: int - wset: int - peak_paged_pool: int - paged_pool: int - peak_nonpaged_pool: int - nonpaged_pool: int - pagefile: int - peak_pagefile: int - private: int - uss: int - - class pmmap_grouped(NamedTuple): - path: Incomplete - rss: Incomplete - - class pmmap_ext(NamedTuple): - addr: Incomplete - perms: Incomplete - path: Incomplete - rss: Incomplete - - class pio(NamedTuple): - read_count: int - write_count: int - read_bytes: int - write_bytes: int - other_count: int - other_bytes: int - _P = ParamSpec("_P") _R = TypeVar("_R") def convert_dos_path(s: str) -> str: ... def getpagesize() -> int: ... - def virtual_memory() -> svmem: ... - def swap_memory() -> _common.sswap: ... + def virtual_memory() -> ntp.svmem: ... + def swap_memory() -> ntp.sswap: ... + heap_info = _psutil_windows.heap_info + heap_trim = _psutil_windows.heap_trim disk_io_counters = _psutil_windows.disk_io_counters - def disk_usage(path: str) -> _common.sdiskusage: ... - def disk_partitions(all: bool) -> list[_common.sdiskpart]: ... - def cpu_times() -> scputimes: ... - def per_cpu_times() -> list[scputimes]: ... + def disk_usage(path: str) -> ntp.sdiskusage: ... + def disk_partitions(all: bool) -> list[ntp.sdiskpart]: ... + def cpu_times() -> ntp.scputimes: ... + def per_cpu_times() -> list[ntp.scputimes]: ... def cpu_count_logical() -> int | None: ... def cpu_count_cores() -> int | None: ... - def cpu_stats() -> _common.scpustats: ... - def cpu_freq() -> list[_common.scpufreq]: ... + def cpu_stats() -> ntp.scpustats: ... + def cpu_freq() -> list[ntp.scpufreq]: ... def getloadavg() -> tuple[float, float, float]: ... @overload - def net_connections(kind: str, _pid: Literal[-1] = -1) -> list[_common.sconn]: ... + def net_connections(kind: str, _pid: Literal[-1] = -1) -> list[ntp.sconn]: ... @overload - def net_connections(kind: str, _pid: int = -1) -> list[_common.pconn]: ... - def net_if_stats() -> dict[str, _common.snicstats]: ... + def net_connections(kind: str, _pid: int = -1) -> list[ntp.pconn]: ... + def net_if_stats() -> dict[str, ntp.snicstats]: ... def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ... def net_if_addrs() -> list[tuple[str, int, str, str | None, None, None]]: ... - def sensors_battery() -> _common.sbattery | None: ... + def sensors_battery() -> ntp.sbattery | None: ... def boot_time() -> float: ... - def users() -> list[_common.suser]: ... + def users() -> list[ntp.suser]: ... def win_service_iter() -> Iterator[WindowsService]: ... def win_service_get(name: str) -> WindowsService: ... @type_check_only @@ -207,8 +147,8 @@ if sys.platform == "win32": def cmdline(self) -> list[str]: ... def environ(self) -> dict[str, str]: ... def ppid(self) -> int: ... - def memory_info(self) -> pmem: ... - def memory_full_info(self) -> pfullmem: ... + def memory_info(self) -> ntp.pmem: ... + def memory_full_info(self) -> ntp.pfullmem: ... def memory_maps(self) -> Iterator[tuple[str, str, str, int]]: ... def kill(self) -> None: ... def send_signal(self, sig: Literal[Signals.SIGTERM, Signals.CTRL_C_EVENT, Signals.CTRL_BREAK_EVENT]) -> None: ... @@ -216,20 +156,20 @@ if sys.platform == "win32": def username(self) -> str: ... def create_time(self, fast_only: bool = False) -> float: ... def num_threads(self) -> int: ... - def threads(self) -> list[_common.pthread]: ... - def cpu_times(self) -> _common.pcputimes: ... + def threads(self) -> list[ntp.pthread]: ... + def cpu_times(self) -> ntp.pcputimes: ... def suspend(self) -> None: ... def resume(self) -> None: ... def cwd(self) -> str: ... - def open_files(self) -> list[_common.popenfile]: ... - def net_connections(self, kind: str = "inet") -> list[_common.pconn]: ... + def open_files(self) -> list[ntp.popenfile]: ... + def net_connections(self, kind: str = "inet") -> list[ntp.pconn]: ... def nice_get(self) -> Priority: ... def nice_set(self, value: int) -> None: ... def ionice_get(self) -> IOPriority: ... def ionice_set(self, ioclass: int, value: None) -> None: ... - def io_counters(self) -> pio: ... + def io_counters(self) -> ntp.pio: ... def status(self) -> Literal["stopped", "running"]: ... def cpu_affinity_get(self) -> list[int]: ... def cpu_affinity_set(self, value: Iterable[int]) -> None: ... def num_handles(self) -> int: ... - def num_ctx_switches(self) -> _common.pctxsw: ... + def num_ctx_switches(self) -> ntp.pctxsw: ...