11import enum
2- from _typeshed import Incomplete , StrOrBytesPath , SupportsWrite
2+ import io
3+ import threading
4+ from _typeshed import ConvertibleToFloat , FileDescriptorOrPath , Incomplete , StrOrBytesPath , SupportsWrite
35from collections .abc import Callable
46from socket import AF_INET6 as AF_INET6 , AddressFamily , SocketKind
5- from typing import Literal , NamedTuple , TypeVar , overload
6-
7- POSIX : bool
8- WINDOWS : bool
9- LINUX : bool
10- MACOS : bool
11- OSX : bool
12- FREEBSD : bool
13- OPENBSD : bool
14- NETBSD : bool
15- BSD : bool
16- SUNOS : bool
17- AIX : bool
18-
19- STATUS_RUNNING : Literal ["running" ]
20- STATUS_SLEEPING : Literal ["sleeping" ]
21- STATUS_DISK_SLEEP : Literal ["disk-sleep" ]
22- STATUS_STOPPED : Literal ["stopped" ]
23- STATUS_TRACING_STOP : Literal ["tracing-stop" ]
24- STATUS_ZOMBIE : Literal ["zombie" ]
25- STATUS_DEAD : Literal ["dead" ]
26- STATUS_WAKE_KILL : Literal ["wake-kill" ]
27- STATUS_WAKING : Literal ["waking" ]
28- STATUS_IDLE : Literal ["idle" ]
29- STATUS_LOCKED : Literal ["locked" ]
30- STATUS_WAITING : Literal ["waiting" ]
31- STATUS_SUSPENDED : Literal ["suspended" ]
32- STATUS_PARKED : Literal ["parked" ]
33-
34- CONN_ESTABLISHED : str
35- CONN_SYN_SENT : str
36- CONN_SYN_RECV : str
37- CONN_FIN_WAIT1 : str
38- CONN_FIN_WAIT2 : str
39- CONN_TIME_WAIT : str
40- CONN_CLOSE : str
41- CONN_CLOSE_WAIT : str
42- CONN_LAST_ACK : str
43- CONN_LISTEN : str
44- CONN_CLOSING : str
45- CONN_NONE : str
46- NIC_DUPLEX_FULL : int
47- NIC_DUPLEX_HALF : int
48- NIC_DUPLEX_UNKNOWN : int
7+ from typing import BinaryIO , Final , NamedTuple , SupportsIndex , TypeVar , overload
8+ from typing_extensions import ParamSpec
9+
10+ POSIX : Final [bool ]
11+ WINDOWS : Final [bool ]
12+ LINUX : Final [bool ]
13+ MACOS : Final [bool ]
14+ OSX : Final [bool ]
15+ FREEBSD : Final [bool ]
16+ OPENBSD : Final [bool ]
17+ NETBSD : Final [bool ]
18+ BSD : Final [bool ]
19+ SUNOS : Final [bool ]
20+ AIX : Final [bool ]
21+
22+ STATUS_RUNNING : Final = "running"
23+ STATUS_SLEEPING : Final = "sleeping"
24+ STATUS_DISK_SLEEP : Final = "disk-sleep"
25+ STATUS_STOPPED : Final = "stopped"
26+ STATUS_TRACING_STOP : Final = "tracing-stop"
27+ STATUS_ZOMBIE : Final = "zombie"
28+ STATUS_DEAD : Final = "dead"
29+ STATUS_WAKE_KILL : Final = "wake-kill"
30+ STATUS_WAKING : Final = "waking"
31+ STATUS_IDLE : Final = "idle"
32+ STATUS_LOCKED : Final = "locked"
33+ STATUS_WAITING : Final = "waiting"
34+ STATUS_SUSPENDED : Final = "suspended"
35+ STATUS_PARKED : Final = "parked"
36+
37+ CONN_ESTABLISHED : Final = "ESTABLISHED"
38+ CONN_SYN_SENT : Final = "SYN_SENT"
39+ CONN_SYN_RECV : Final = "SYN_RECV"
40+ CONN_FIN_WAIT1 : Final = "FIN_WAIT1"
41+ CONN_FIN_WAIT2 : Final = "FIN_WAIT2"
42+ CONN_TIME_WAIT : Final = "TIME_WAIT"
43+ CONN_CLOSE : Final = "CLOSE"
44+ CONN_CLOSE_WAIT : Final = "CLOSE_WAIT"
45+ CONN_LAST_ACK : Final = "LAST_ACK"
46+ CONN_LISTEN : Final = "LISTEN"
47+ CONN_CLOSING : Final = "CLOSING"
48+ CONN_NONE : Final = "NONE"
4949
5050class NicDuplex (enum .IntEnum ):
5151 NIC_DUPLEX_FULL = 2
5252 NIC_DUPLEX_HALF = 1
5353 NIC_DUPLEX_UNKNOWN = 0
5454
55- POWER_TIME_UNKNOWN : int
56- POWER_TIME_UNLIMITED : int
55+ NIC_DUPLEX_FULL : Final = NicDuplex .NIC_DUPLEX_FULL
56+ NIC_DUPLEX_HALF : Final = NicDuplex .NIC_DUPLEX_HALF
57+ NIC_DUPLEX_UNKNOWN : Final = NicDuplex .NIC_DUPLEX_UNKNOWN
5758
5859class BatteryTime (enum .IntEnum ):
5960 POWER_TIME_UNKNOWN = - 1
6061 POWER_TIME_UNLIMITED = - 2
6162
62- ENCODING : str
63- ENCODING_ERRS : str
63+ POWER_TIME_UNKNOWN : Final = BatteryTime .POWER_TIME_UNKNOWN
64+ POWER_TIME_UNLIMITED : Final = BatteryTime .POWER_TIME_UNLIMITED
65+
66+ ENCODING : Final [str ]
67+ ENCODING_ERRS : Final [str ]
6468
6569class sswap (NamedTuple ):
6670 total : int
@@ -210,44 +214,42 @@ class addr(NamedTuple):
210214conn_tmap : dict [str , tuple [list [AddressFamily ], list [SocketKind ]]]
211215
212216class Error (Exception ):
213- __module__ : str
214- msg : Incomplete
217+ msg : str
215218 def __init__ (self , msg : str = ...) -> None : ...
216219
217220class NoSuchProcess (Error ):
218- __module__ : str
219- pid : Incomplete
220- name : Incomplete
221- msg : Incomplete
222- def __init__ (self , pid , name = None , msg = None ) -> None : ...
221+ pid : int
222+ name : str | None
223+ msg : str
224+ def __init__ (self , pid : int , name : str | None = None , msg : str | None = None ) -> None : ...
223225
224226class ZombieProcess (NoSuchProcess ):
225- __module__ : str
226- pid : Incomplete
227- ppid : Incomplete
228- name : Incomplete
229- msg : Incomplete
230- def __init__ (self , pid , name = None , ppid = None , msg = None ) -> None : ...
227+ ppid : int | None
228+ def __init__ (self , pid : int , name : str | None = None , ppid : int | None = None , msg : str | None = None ) -> None : ...
231229
232230class AccessDenied (Error ):
233- __module__ : str
234- pid : Incomplete
235- name : Incomplete
236- msg : Incomplete
237- def __init__ (self , pid = None , name = None , msg = None ) -> None : ...
231+ pid : int | None
232+ name : str | None
233+ msg : str
234+ def __init__ (self , pid : int | None = None , name : str | None = None , msg : str | None = None ) -> None : ...
238235
239236class TimeoutExpired (Error ):
240- __module__ : str
241- seconds : Incomplete
242- pid : Incomplete
243- name : Incomplete
244- def __init__ (self , seconds , pid = None , name = None ) -> None : ...
237+ seconds : float
238+ pid : int | None
239+ name : str | None
240+ msg : str
241+ def __init__ (self , seconds : float , pid : int | None = None , name : str | None = None ) -> None : ...
242+
243+ _P = ParamSpec ("_P" )
244+ _R = TypeVar ("_R" )
245+
246+ def usage_percent (used : ConvertibleToFloat , total : float , round_ : SupportsIndex | None = None ) -> float : ...
245247
246- _Func = TypeVar ("_Func" , bound = Callable [..., Incomplete ])
248+ # returned function has `cache_clear()` attribute:
249+ def memoize (fun : Callable [_P , _R ]) -> Callable [_P , _R ]: ...
247250
248- def usage_percent (used , total , round_ : int | None = None ) -> float : ...
249- def memoize (fun : _Func ) -> _Func : ...
250- def memoize_when_activated (fun : _Func ) -> _Func : ...
251+ # returned function has `cache_activate(proc)` and `cache_deactivate(proc)` attributes:
252+ def memoize_when_activated (fun : Callable [_P , _R ]) -> Callable [_P , _R ]: ...
251253def isfile_strict (path : StrOrBytesPath ) -> bool : ...
252254def path_exists_strict (path : StrOrBytesPath ) -> bool : ...
253255def supports_ipv6 () -> bool : ...
@@ -258,29 +260,30 @@ def socktype_to_enum(num: int) -> SocketKind: ...
258260def conn_to_ntuple (fd : int , fam : int , type_ : int , laddr , raddr , status : str , status_map , pid : int ) -> sconn : ...
259261@overload
260262def conn_to_ntuple (fd : int , fam : int , type_ : int , laddr , raddr , status : str , status_map , pid : None = None ) -> pconn : ...
261- def deprecated_method (replacement : str ) -> Callable [[_Func ], _Func ]: ...
263+ def deprecated_method (replacement : str ) -> Callable [[Callable [ _P , _R ]], Callable [ _P , _R ] ]: ...
262264
263265class _WrapNumbers :
264- lock : Incomplete
265- cache : Incomplete
266- reminders : Incomplete
267- reminder_keys : Incomplete
266+ lock : threading . Lock
267+ cache : dict [ Incomplete , Incomplete ]
268+ reminders : dict [ Incomplete , Incomplete ]
269+ reminder_keys : dict [ Incomplete , Incomplete ]
268270 def __init__ (self ) -> None : ...
269271 def run (self , input_dict , name ): ...
270272 def cache_clear (self , name = None ) -> None : ...
271- def cache_info (self ): ...
273+ def cache_info (self ) -> tuple [ dict [ Incomplete , Incomplete ], dict [ Incomplete , Incomplete ], dict [ Incomplete , Incomplete ]] : ...
272274
273275def wrap_numbers (input_dict , name : str ): ...
274- def open_binary (fname ) : ...
275- def open_text (fname ) : ...
276- def cat (fname , fallback = ..., _open = ...): ...
277- def bcat (fname , fallback = ...): ...
276+ def open_binary (fname : FileDescriptorOrPath ) -> BinaryIO : ...
277+ def open_text (fname : FileDescriptorOrPath ) -> io . TextIOWrapper : ...
278+ def cat (fname : FileDescriptorOrPath , fallback = ..., _open = ...): ...
279+ def bcat (fname : FileDescriptorOrPath , fallback = ...): ...
278280def bytes2human (n : int , format : str = "%(value).1f%(symbol)s" ) -> str : ...
279281def get_procfs_path () -> str : ...
282+ def decode (s : bytes ) -> str : ...
280283def term_supports_colors (file : SupportsWrite [str ] = ...) -> bool : ...
281284def hilite (s : str , color : str | None = None , bold : bool = False ) -> str : ...
282285def print_color (s : str , color : str | None = None , bold : bool = False , file : SupportsWrite [str ] = ...) -> None : ...
283- def debug (msg ) -> None : ...
286+ def debug (msg : str | Exception ) -> None : ...
284287
285288__all__ = [
286289 # OS constants
0 commit comments