From 6188a3eec789b94cacd0c46e929321daad04b4b5 Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Mon, 6 Sep 2021 21:37:53 +0300 Subject: [PATCH] Improves `psutil/_common.pyi` (#6010) * Improves `psutil/_common.pyi` In this iteration I've fixed the most obvious types and corrected several mistakes. We can go deeper in the next iteration(s). * We don't need to import `Union` * Update _common.pyi * Update _common.pyi * Update _common.pyi --- stubs/psutil/psutil/_common.pyi | 52 ++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/stubs/psutil/psutil/_common.pyi b/stubs/psutil/psutil/_common.pyi index 3cdd50fdc..846fb9807 100644 --- a/stubs/psutil/psutil/_common.pyi +++ b/stubs/psutil/psutil/_common.pyi @@ -1,17 +1,17 @@ import enum -from typing import Any, NamedTuple +from typing import Any, Callable, NamedTuple, TypeVar -POSIX: Any -WINDOWS: Any -LINUX: Any -MACOS: Any -OSX: Any -FREEBSD: Any -OPENBSD: Any -NETBSD: Any -BSD: Any -SUNOS: Any -AIX: Any +POSIX: bool +WINDOWS: bool +LINUX: bool +MACOS: bool +OSX: bool +FREEBSD: bool +OPENBSD: bool +NETBSD: bool +BSD: bool +SUNOS: bool +AIX: bool STATUS_RUNNING: str STATUS_SLEEPING: str STATUS_DISK_SLEEP: str @@ -54,8 +54,8 @@ class BatteryTime(enum.IntEnum): POWER_TIME_UNKNOWN: int POWER_TIME_UNLIMITED: int -ENCODING: Any -ENCODING_ERRS: Any +ENCODING: str +ENCODING_ERRS: str class sswap(NamedTuple): total: Any @@ -239,16 +239,19 @@ class TimeoutExpired(Error): name: Any def __init__(self, seconds, pid: Any | None = ..., name: Any | None = ...) -> None: ... -def usage_percent(used, total, round_: Any | None = ...): ... -def memoize(fun): ... -def isfile_strict(path): ... -def path_exists_strict(path): ... -def supports_ipv6(): ... +_Func = TypeVar("_Func", bound=Callable[..., Any]) + +def usage_percent(used, total, round_: int | None = ...) -> float: ... +def memoize(fun: _Func) -> _Func: ... +def memoize_when_activated(fun: _Func) -> _Func: ... +def isfile_strict(path) -> bool: ... +def path_exists_strict(path) -> bool: ... +def supports_ipv6() -> bool: ... def parse_environ_block(data): ... def sockfam_to_enum(num): ... def socktype_to_enum(num): ... def conn_to_ntuple(fd, fam, type_, laddr, raddr, status, status_map, pid: Any | None = ...): ... -def deprecated_method(replacement): ... +def deprecated_method(replacement: str) -> Callable[[_Func], _Func]: ... class _WrapNumbers: lock: Any @@ -261,8 +264,9 @@ class _WrapNumbers: def cache_info(self): ... def wrap_numbers(input_dict, name): ... -def bytes2human(n, format: str = ...): ... -def term_supports_colors(file=...): ... -def hilite(s, color: Any | None = ..., bold: bool = ...): ... -def print_color(s, color: Any | None = ..., bold: bool = ..., file=...) -> None: ... +def bytes2human(n: int, format: str = ...) -> str: ... +def get_procfs_path(): ... +def term_supports_colors(file=...) -> bool: ... +def hilite(s: str, color: str | None = ..., bold: bool = ...) -> str: ... +def print_color(s: str, color: str | None = ..., bold: bool = ..., file=...) -> None: ... def debug(msg) -> None: ...