Skip to content

Commit 0d25c8c

Browse files
authored
[psutil] Complete OSX stubs (#15030)
1 parent f8cdc0b commit 0d25c8c

File tree

3 files changed

+183
-158
lines changed

3 files changed

+183
-158
lines changed

stubs/psutil/psutil/_psosx.pyi

Lines changed: 119 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,119 @@
1-
from _typeshed import Incomplete
2-
from typing import NamedTuple
3-
4-
from psutil._common import (
5-
AccessDenied as AccessDenied,
6-
NoSuchProcess as NoSuchProcess,
7-
ZombieProcess as ZombieProcess,
8-
conn_tmap as conn_tmap,
9-
conn_to_ntuple as conn_to_ntuple,
10-
isfile_strict as isfile_strict,
11-
parse_environ_block as parse_environ_block,
12-
usage_percent as usage_percent,
13-
)
14-
15-
__extra__all__: Incomplete
16-
PAGESIZE: Incomplete
17-
AF_LINK: Incomplete
18-
TCP_STATUSES: Incomplete
19-
PROC_STATUSES: Incomplete
20-
kinfo_proc_map: Incomplete
21-
pidtaskinfo_map: Incomplete
22-
23-
class scputimes(NamedTuple):
24-
user: float
25-
nice: float
26-
system: float
27-
idle: float
28-
29-
class svmem(NamedTuple):
30-
total: int
31-
available: int
32-
percent: float
33-
used: int
34-
free: int
35-
active: int
36-
inactive: int
37-
wired: int
38-
39-
class pmem(NamedTuple):
40-
rss: Incomplete
41-
vms: Incomplete
42-
pfaults: Incomplete
43-
pageins: Incomplete
44-
45-
class pfullmem(NamedTuple):
46-
rss: Incomplete
47-
vms: Incomplete
48-
pfaults: Incomplete
49-
pageins: Incomplete
50-
uss: Incomplete
51-
52-
def virtual_memory() -> svmem: ...
53-
def swap_memory(): ...
54-
def cpu_times(): ...
55-
def per_cpu_times(): ...
56-
def cpu_count_logical(): ...
57-
def cpu_count_cores() -> int | None: ...
58-
def cpu_stats(): ...
59-
def cpu_freq(): ...
60-
61-
disk_usage: Incomplete
62-
disk_io_counters: Incomplete
63-
64-
def disk_partitions(all: bool = False): ...
65-
def sensors_battery(): ...
66-
67-
net_io_counters: Incomplete
68-
net_if_addrs: Incomplete
69-
70-
def net_connections(kind: str = "inet"): ...
71-
def net_if_stats(): ...
72-
def boot_time(): ...
73-
def users(): ...
74-
def pids(): ...
75-
76-
pid_exists: Incomplete
77-
78-
def is_zombie(pid): ...
79-
def wrap_exceptions(fun): ...
80-
81-
class Process:
82-
__slots__ = ["_cache", "_name", "_ppid", "pid"]
83-
pid: Incomplete
84-
def __init__(self, pid) -> None: ...
85-
def oneshot_enter(self) -> None: ...
86-
def oneshot_exit(self) -> None: ...
87-
def name(self): ...
88-
def exe(self): ...
89-
def cmdline(self): ...
90-
def environ(self): ...
91-
def ppid(self): ...
92-
def cwd(self): ...
93-
def uids(self): ...
94-
def gids(self): ...
95-
def terminal(self): ...
96-
def memory_info(self): ...
97-
def memory_full_info(self): ...
98-
def cpu_times(self): ...
99-
def create_time(self): ...
100-
def num_ctx_switches(self): ...
101-
def num_threads(self): ...
102-
def open_files(self): ...
103-
def net_connections(self, kind: str = "inet"): ...
104-
def num_fds(self): ...
105-
def wait(self, timeout=None): ...
106-
def nice_get(self): ...
107-
def nice_set(self, value): ...
108-
def status(self): ...
109-
def threads(self): ...
1+
import sys
2+
3+
if sys.platform == "darwin":
4+
from collections.abc import Callable
5+
from typing import Final, NamedTuple, TypeVar
6+
from typing_extensions import ParamSpec
7+
8+
from psutil._common import (
9+
AccessDenied as AccessDenied,
10+
NoSuchProcess as NoSuchProcess,
11+
ZombieProcess as ZombieProcess,
12+
conn_tmap as conn_tmap,
13+
conn_to_ntuple as conn_to_ntuple,
14+
isfile_strict as isfile_strict,
15+
memoize_when_activated as memoize_when_activated,
16+
parse_environ_block as parse_environ_block,
17+
usage_percent as usage_percent,
18+
)
19+
20+
from . import _common, _psposix, _psutil_osx, _psutil_posix
21+
22+
_P = ParamSpec("_P")
23+
_R = TypeVar("_R")
24+
25+
__extra__all__: Final[list[str]]
26+
PAGESIZE: Final[int]
27+
AF_LINK: Final[int]
28+
TCP_STATUSES: Final[dict[int, str]]
29+
PROC_STATUSES: Final[dict[int, str]]
30+
kinfo_proc_map: Final[dict[str, int]]
31+
pidtaskinfo_map: Final[dict[str, int]]
32+
33+
class scputimes(NamedTuple):
34+
user: float
35+
nice: float
36+
system: float
37+
idle: float
38+
39+
class svmem(NamedTuple):
40+
total: int
41+
available: int
42+
percent: float
43+
used: int
44+
free: int
45+
active: int
46+
inactive: int
47+
wired: int
48+
49+
class pmem(NamedTuple):
50+
rss: int
51+
vms: int
52+
pfaults: int
53+
pageins: int
54+
55+
class pfullmem(NamedTuple):
56+
rss: int
57+
vms: int
58+
pfaults: int
59+
pageins: int
60+
uss: int
61+
62+
def virtual_memory() -> svmem: ...
63+
def swap_memory() -> _common.sswap: ...
64+
def cpu_times() -> scputimes: ...
65+
def per_cpu_times() -> list[scputimes]: ...
66+
def cpu_count_logical() -> int | None: ...
67+
def cpu_count_cores() -> int | None: ...
68+
def cpu_stats() -> _common.scpustats: ...
69+
def cpu_freq() -> list[_common.scpufreq]: ...
70+
71+
disk_usage = _psposix.disk_usage
72+
disk_io_counters = _psutil_osx.disk_io_counters
73+
74+
def disk_partitions(all: bool = False) -> list[_common.sdiskpart]: ...
75+
def sensors_battery() -> _common.sbattery | None: ...
76+
77+
net_io_counters = _psutil_osx.net_io_counters
78+
net_if_addrs = _psutil_posix.net_if_addrs
79+
80+
def net_connections(kind: str = "inet") -> list[_common.sconn]: ...
81+
def net_if_stats() -> dict[str, _common.snicstats]: ...
82+
def boot_time() -> float: ...
83+
def users() -> list[_common.suser]: ...
84+
def pids() -> list[int]: ...
85+
86+
pid_exists = _psposix.pid_exists
87+
88+
def is_zombie(pid: int) -> bool: ...
89+
def wrap_exceptions(fun: Callable[_P, _R]) -> Callable[_P, _R]: ...
90+
91+
class Process:
92+
__slots__ = ["_cache", "_name", "_ppid", "pid"]
93+
pid: int
94+
def __init__(self, pid: int) -> None: ...
95+
def oneshot_enter(self) -> None: ...
96+
def oneshot_exit(self) -> None: ...
97+
def name(self) -> str: ...
98+
def exe(self) -> str: ...
99+
def cmdline(self) -> list[str]: ...
100+
def environ(self) -> dict[str, str]: ...
101+
def ppid(self) -> int: ...
102+
def cwd(self) -> str: ...
103+
def uids(self) -> _common.puids: ...
104+
def gids(self) -> _common.puids: ...
105+
def terminal(self) -> str | None: ...
106+
def memory_info(self) -> pmem: ...
107+
def memory_full_info(self) -> pfullmem: ...
108+
def cpu_times(self) -> _common.pcputimes: ...
109+
def create_time(self) -> float: ...
110+
def num_ctx_switches(self) -> _common.pctxsw: ...
111+
def num_threads(self) -> int: ...
112+
def open_files(self) -> list[_common.popenfile]: ...
113+
def net_connections(self, kind: str = "inet"): ...
114+
def num_fds(self) -> int: ...
115+
def wait(self, timeout: float | None = None): ...
116+
def nice_get(self): ...
117+
def nice_set(self, value): ...
118+
def status(self) -> str: ...
119+
def threads(self) -> list[_common.pthread]: ...
Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,64 @@
1-
PSUTIL_CONN_NONE: int
2-
SIDL: int
3-
SRUN: int
4-
SSLEEP: int
5-
SSTOP: int
6-
SZOMB: int
7-
TCPS_CLOSED: int
8-
TCPS_CLOSE_WAIT: int
9-
TCPS_CLOSING: int
10-
TCPS_ESTABLISHED: int
11-
TCPS_FIN_WAIT_1: int
12-
TCPS_FIN_WAIT_2: int
13-
TCPS_LAST_ACK: int
14-
TCPS_LISTEN: int
15-
TCPS_SYN_RECEIVED: int
16-
TCPS_SYN_SENT: int
17-
TCPS_TIME_WAIT: int
18-
version: int
1+
import sys
192

20-
def boot_time(*args, **kwargs): ...
21-
def check_pid_range(pid: int, /) -> None: ...
22-
def cpu_count_cores(*args, **kwargs): ...
23-
def cpu_count_logical(*args, **kwargs): ...
24-
def cpu_freq(*args, **kwargs): ...
25-
def cpu_stats(*args, **kwargs): ...
26-
def cpu_times(*args, **kwargs): ...
27-
def disk_io_counters(*args, **kwargs): ...
28-
def disk_partitions(*args, **kwargs): ...
29-
def disk_usage_used(*args, **kwargs): ...
30-
def net_io_counters(*args, **kwargs): ...
31-
def per_cpu_times(*args, **kwargs): ...
32-
def pids(*args, **kwargs): ...
33-
def proc_cmdline(*args, **kwargs): ...
34-
def proc_net_connections(*args, **kwargs): ...
35-
def proc_cwd(*args, **kwargs): ...
36-
def proc_environ(*args, **kwargs): ...
37-
def proc_exe(*args, **kwargs): ...
38-
def proc_kinfo_oneshot(*args, **kwargs): ...
39-
def proc_memory_uss(*args, **kwargs): ...
40-
def proc_name(*args, **kwargs): ...
41-
def proc_num_fds(*args, **kwargs): ...
42-
def proc_open_files(*args, **kwargs): ...
43-
def proc_pidtaskinfo_oneshot(*args, **kwargs): ...
44-
def proc_threads(*args, **kwargs): ...
45-
def sensors_battery(*args, **kwargs): ...
46-
def set_debug(*args, **kwargs): ...
47-
def swap_mem(*args, **kwargs): ...
48-
def users(*args, **kwargs): ...
49-
def virtual_mem(*args, **kwargs): ...
3+
if sys.platform == "darwin":
4+
from _typeshed import StrOrBytesPath
5+
from collections.abc import Sequence
6+
from socket import AddressFamily, SocketKind
7+
from typing import Final, TypeVar
8+
9+
_T = TypeVar("_T")
10+
11+
version: Final[int]
12+
SIDL: Final = 1
13+
SRUN: Final = 2
14+
SSLEEP: Final = 3
15+
SSTOP: Final = 4
16+
SZOMB: Final = 5
17+
TCPS_CLOSED: Final = 0
18+
TCPS_CLOSING: Final = 7
19+
TCPS_CLOSE_WAIT: Final = 5
20+
TCPS_LISTEN: Final = 1
21+
TCPS_ESTABLISHED: Final = 4
22+
TCPS_SYN_SENT: Final = 2
23+
TCPS_SYN_RECEIVED: Final = 3
24+
TCPS_FIN_WAIT_1: Final = 6
25+
TCPS_FIN_WAIT_2: Final = 9
26+
TCPS_LAST_ACK: Final = 8
27+
TCPS_TIME_WAIT: Final = 10
28+
PSUTIL_CONN_NONE: Final = 128
29+
30+
def proc_cmdline(pid: int, /) -> list[str]: ...
31+
def proc_cwd(pid: int, /) -> str: ...
32+
def proc_environ(pid: int, /) -> str: ...
33+
def proc_exe(pid: int, /) -> str: ...
34+
def proc_kinfo_oneshot(pid: int, /) -> tuple[int, int, int, int, int, int, int, float, int, str]: ...
35+
def proc_memory_uss(pid: int, /) -> int: ...
36+
def proc_name(pid: int, /) -> str: ...
37+
def proc_net_connections(
38+
pid: int, af_filter: Sequence[AddressFamily | int | None], type_filter: Sequence[SocketKind | int | None], /
39+
) -> list[
40+
tuple[int, int, int, tuple[str | None, int], tuple[str | None, int] | tuple[()], int]
41+
| tuple[int, int, int, str, str, int]
42+
]: ...
43+
def proc_num_fds(pid: int, /) -> int: ...
44+
def proc_open_files(pid: int, /) -> list[tuple[str, int]]: ...
45+
def proc_pidtaskinfo_oneshot(pid: int, /) -> tuple[float, float, int, int, int, int, int, int]: ...
46+
def proc_threads(pid: int, /) -> list[tuple[int, float, float]]: ...
47+
def boot_time() -> float: ...
48+
def cpu_count_cores() -> int | None: ...
49+
def cpu_count_logical() -> int | None: ...
50+
def cpu_freq() -> tuple[int, int, int]: ...
51+
def cpu_stats() -> tuple[int, int, int, int, int]: ...
52+
def cpu_times() -> tuple[float, float, float, float]: ...
53+
def disk_io_counters() -> dict[str, tuple[int, int, int, int, int, int]]: ...
54+
def disk_partitions() -> list[tuple[str, str, str, str]]: ...
55+
def disk_usage_used(mount_point: StrOrBytesPath, default: _T, /) -> int | _T: ...
56+
def net_io_counters() -> dict[str, tuple[int, int, int, int, int, int, int, int]]: ...
57+
def per_cpu_times() -> list[tuple[float, float, float, float]]: ...
58+
def pids() -> list[int]: ...
59+
def sensors_battery() -> tuple[int, int, int]: ...
60+
def swap_mem() -> tuple[int, int, int, int, int]: ...
61+
def users() -> list[tuple[str, str, str, float, int]]: ...
62+
def virtual_mem() -> tuple[int, int, int, int, int, int]: ...
63+
def check_pid_range(pid: int, /) -> None: ...
64+
def set_debug(value: bool, /) -> None: ...

stubs/psutil/psutil/_pswindows.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if sys.platform == "win32":
3333

3434
from . import _common
3535

36-
__extra__all__: list[str]
36+
__extra__all__: Final[list[str]]
3737
CONN_DELETE_TCB: Final = "DELETE_TCB"
3838
ERROR_PARTIAL_COPY: Final = 299
3939
PYPY: Final[bool]

0 commit comments

Comments
 (0)