From b84af5a4afeab74705e4e6fdae8774d8a88b452e Mon Sep 17 00:00:00 2001 From: Nikita Sobolev Date: Tue, 5 Oct 2021 14:30:00 +0300 Subject: [PATCH] Add several missing type annotations to `psutil._common` (#6104) --- stubs/psutil/psutil/__init__.pyi | 3 ++- stubs/psutil/psutil/_common.pyi | 41 ++++++++++++++++++-------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/stubs/psutil/psutil/__init__.pyi b/stubs/psutil/psutil/__init__.pyi index 881cce630..84561eb1b 100644 --- a/stubs/psutil/psutil/__init__.pyi +++ b/stubs/psutil/psutil/__init__.pyi @@ -51,6 +51,7 @@ from ._common import ( pcputimes, pctxsw, pgids, + pionice, popenfile, pthread, puids, @@ -129,7 +130,7 @@ class Process: def num_fds(self) -> int: ... if sys.platform != "darwin": def io_counters(self): ... - def ionice(self, ioclass: int | None = ..., value: int | None = ...) -> int: ... + def ionice(self, ioclass: int | None = ..., value: int | None = ...) -> pionice: ... if sys.platform == "linux": def rlimit(self, resource: int, limits: tuple[int, int] | None = ...): ... if sys.platform != "darwin": diff --git a/stubs/psutil/psutil/_common.pyi b/stubs/psutil/psutil/_common.pyi index 18aca12b4..22b08bdb3 100644 --- a/stubs/psutil/psutil/_common.pyi +++ b/stubs/psutil/psutil/_common.pyi @@ -1,5 +1,7 @@ import enum -from typing import Any, Callable, NamedTuple, TypeVar +from _typeshed import StrOrBytesPath, SupportsWrite +from socket import AddressFamily, SocketKind +from typing import Any, Callable, NamedTuple, TypeVar, overload POSIX: bool WINDOWS: bool @@ -106,15 +108,15 @@ class suser(NamedTuple): class sconn(NamedTuple): fd: int - family: Any - type: Any + family: AddressFamily + type: SocketKind laddr: str raddr: str status: str pid: int class snicaddr(NamedTuple): - family: Any + family: AddressFamily address: str netmask: str | None broadcast: str | None @@ -122,7 +124,7 @@ class snicaddr(NamedTuple): class snicstats(NamedTuple): isup: bool - duplex: Any + duplex: int speed: int mtu: int @@ -184,7 +186,7 @@ class pio(NamedTuple): write_bytes: int class pionice(NamedTuple): - ioclass: Any + ioclass: int value: int class pctxsw(NamedTuple): @@ -193,8 +195,8 @@ class pctxsw(NamedTuple): class pconn(NamedTuple): fd: int - family: Any - type: Any + family: AddressFamily + type: SocketKind laddr: addr raddr: addr status: str @@ -203,7 +205,7 @@ class addr(NamedTuple): ip: str port: int -conn_tmap: Any +conn_tmap: dict[str, tuple[list[AddressFamily], list[SocketKind]]] class Error(Exception): __module__: str @@ -244,13 +246,16 @@ _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 isfile_strict(path: StrOrBytesPath) -> bool: ... +def path_exists_strict(path: StrOrBytesPath) -> 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 sockfam_to_enum(num: int) -> AddressFamily: ... +def socktype_to_enum(num: int) -> SocketKind: ... +@overload +def conn_to_ntuple(fd: int, fam: int, type_: int, laddr, raddr, status: str, status_map, pid: int) -> sconn: ... +@overload +def conn_to_ntuple(fd: int, fam: int, type_: int, laddr, raddr, status: str, status_map, pid: None = ...) -> pconn: ... def deprecated_method(replacement: str) -> Callable[[_Func], _Func]: ... class _WrapNumbers: @@ -263,10 +268,10 @@ class _WrapNumbers: def cache_clear(self, name: Any | None = ...) -> None: ... def cache_info(self): ... -def wrap_numbers(input_dict, name): ... +def wrap_numbers(input_dict, name: str): ... def bytes2human(n: int, format: str = ...) -> str: ... -def get_procfs_path(): ... -def term_supports_colors(file=...) -> bool: ... +def get_procfs_path() -> str: ... +def term_supports_colors(file: SupportsWrite[str] = ...) -> bool: ... def hilite(s: str, color: str | None = ..., bold: bool = ...) -> str: ... -def print_color(s: str, color: str | None = ..., bold: bool = ..., file=...) -> None: ... +def print_color(s: str, color: str | None = ..., bold: bool = ..., file: SupportsWrite[str] = ...) -> None: ... def debug(msg) -> None: ...