From 64142508889ea3eb1a2d7d6ddef5bab562d1f762 Mon Sep 17 00:00:00 2001 From: crusaderky Date: Mon, 3 Oct 2022 17:25:25 +0100 Subject: [PATCH] psutil: Improve types for disk_io_counters() and net_io_counters() (#8829) --- stubs/psutil/psutil/__init__.pyi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stubs/psutil/psutil/__init__.pyi b/stubs/psutil/psutil/__init__.pyi index 2330710a2..2ffb5465f 100644 --- a/stubs/psutil/psutil/__init__.pyi +++ b/stubs/psutil/psutil/__init__.pyi @@ -2,7 +2,7 @@ import sys from _typeshed import Self from collections.abc import Callable, Iterable, Iterator from contextlib import AbstractContextManager -from typing import Any +from typing import Any, overload from typing_extensions import Literal, TypeAlias from ._common import ( @@ -225,8 +225,14 @@ def virtual_memory() -> svmem: ... def swap_memory() -> sswap: ... def disk_usage(path: str) -> sdiskusage: ... def disk_partitions(all: bool = ...) -> list[sdiskpart]: ... -def disk_io_counters(perdisk: bool = ..., nowrap: bool = ...) -> sdiskio: ... -def net_io_counters(pernic: bool = ..., nowrap: bool = ...) -> snetio: ... +@overload +def disk_io_counters(perdisk: Literal[False] = ..., nowrap: bool = ...) -> sdiskio | None: ... +@overload +def disk_io_counters(perdisk: Literal[True], nowrap: bool = ...) -> dict[str, sdiskio]: ... +@overload +def net_io_counters(pernic: Literal[False] = ..., nowrap: bool = ...) -> snetio: ... +@overload +def net_io_counters(pernic: Literal[True], nowrap: bool = ...) -> dict[str, snetio]: ... def net_connections(kind: str = ...) -> list[sconn]: ... def net_if_addrs() -> dict[str, list[snicaddr]]: ... def net_if_stats() -> dict[str, snicstats]: ...