Skip to content

Commit

Permalink
Fix types for psutil.cpu_* functions (#12602)
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhdu authored Aug 31, 2024
1 parent f87041e commit 23d867e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 30 deletions.
25 changes: 19 additions & 6 deletions stubs/psutil/psutil/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ if sys.platform == "win32":
)

if sys.platform == "linux":
from ._pslinux import pfullmem, pmem, sensors_battery as sensors_battery, svmem
from ._pslinux import pfullmem, pmem, scputimes, sensors_battery as sensors_battery, svmem
elif sys.platform == "darwin":
from ._psosx import pfullmem, pmem, sensors_battery as sensors_battery, svmem
from ._psosx import pfullmem, pmem, scputimes, sensors_battery as sensors_battery, svmem
elif sys.platform == "win32":
from ._pswindows import pfullmem, pmem, sensors_battery as sensors_battery, svmem
from ._pswindows import pfullmem, pmem, scputimes, sensors_battery as sensors_battery, svmem
else:
scputimes = Incomplete

class pmem(Any): ...
class pfullmem(Any): ...
class svmem(Any): ...
Expand Down Expand Up @@ -241,16 +243,27 @@ def wait_procs(
procs: Iterable[Process], timeout: float | None = None, callback: Callable[[Process], object] | None = None
) -> tuple[list[Process], list[Process]]: ...
def cpu_count(logical: bool = True) -> int: ...
def cpu_times(percpu: bool = False): ...
@overload
def cpu_freq(percpu: Literal[False] = ...) -> scpufreq: ...
@overload
def cpu_freq(percpu: Literal[True]) -> list[scpufreq]: ...
@overload
def cpu_times(percpu: Literal[False] = ...) -> scputimes: ...
@overload
def cpu_times(percpu: Literal[True]) -> list[scputimes]: ...
@overload
def cpu_percent(interval: float | None = None, percpu: Literal[False] = False) -> float: ...
@overload
def cpu_percent(interval: float | None, percpu: Literal[True]) -> list[float]: ...
@overload
def cpu_percent(*, percpu: Literal[True]) -> list[float]: ...
def cpu_times_percent(interval: float | None = None, percpu: bool = False): ...
@overload
def cpu_times_percent(interval: float | None = None, percpu: Literal[False] = False) -> scputimes: ...
@overload
def cpu_times_percent(interval: float | None, percpu: Literal[True]) -> list[scputimes]: ...
@overload
def cpu_times_percent(*, percpu: Literal[True]) -> list[scputimes]: ...
def cpu_stats() -> scpustats: ...
def cpu_freq(percpu: bool = False) -> scpufreq: ...
def getloadavg() -> tuple[float, float, float]: ...
def virtual_memory() -> svmem: ...
def swap_memory() -> sswap: ...
Expand Down
8 changes: 4 additions & 4 deletions stubs/psutil/psutil/_psaix.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class pmem(NamedTuple):
pfullmem = pmem

class scputimes(NamedTuple):
user: Incomplete
system: Incomplete
idle: Incomplete
iowait: Incomplete
user: float
system: float
idle: float
iowait: float

class svmem(NamedTuple):
total: Incomplete
Expand Down
10 changes: 5 additions & 5 deletions stubs/psutil/psutil/_psbsd.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class svmem(NamedTuple):
wired: int

class scputimes(NamedTuple):
user: Any
nice: Any
system: Any
idle: Any
irq: Any
user: float
nice: float
system: float
idle: float
irq: float

class pmem(NamedTuple):
rss: Any
Expand Down
25 changes: 19 additions & 6 deletions stubs/psutil/psutil/_pslinux.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,31 @@ class pio(NamedTuple):
write_chars: Any

class pcputimes(NamedTuple):
user: Any
system: Any
children_user: Any
children_system: Any
iowait: Any
user: float
system: float
children_user: float
children_system: float
iowait: float

def readlink(path): ...
def file_flags_to_mode(flags): ...
def is_storage_device(name): ...
def set_scputimes_ntuple(procfs_path) -> None: ...

scputimes: Any
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

prlimit: Any

def calculate_avail_vmem(mems): ...
Expand Down
8 changes: 4 additions & 4 deletions stubs/psutil/psutil/_psosx.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ kinfo_proc_map: Any
pidtaskinfo_map: Any

class scputimes(NamedTuple):
user: Any
nice: Any
system: Any
idle: Any
user: float
nice: float
system: float
idle: float

class svmem(NamedTuple):
total: int
Expand Down
10 changes: 5 additions & 5 deletions stubs/psutil/psutil/_pswindows.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ class IOPriority(enum.IntEnum):
pinfo_map: Any

class scputimes(NamedTuple):
user: Any
system: Any
idle: Any
interrupt: Any
dpc: Any
user: float
system: float
idle: float
interrupt: float
dpc: float

class svmem(NamedTuple):
total: int
Expand Down

0 comments on commit 23d867e

Please sign in to comment.