Skip to content

Commit 121a6f1

Browse files
committed
[psutil] Use more strict pyright settings
1 parent 5d41fd6 commit 121a6f1

3 files changed

Lines changed: 52 additions & 19 deletions

File tree

pyrightconfig.stricter.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"stubs/pika",
7373
"stubs/pony",
7474
"stubs/protobuf",
75-
"stubs/psutil",
75+
"stubs/psutil/psutil/__init__.pyi",
7676
"stubs/psycopg2",
7777
"stubs/pyasn1",
7878
"stubs/pycurl",

stubs/psutil/psutil/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class Process:
199199
def io_counters(self) -> pio: ...
200200
def ionice(self, ioclass: int | None = None, value: int | None = None) -> pionice: ...
201201
def cpu_affinity(self, cpus: list[int] | None = None) -> list[int] | None: ...
202-
def memory_maps(self, grouped: bool = True): ...
202+
def memory_maps(self, grouped: bool = True) -> list[Incomplete]: ...
203203
if sys.platform == "linux":
204204
def rlimit(self, resource: int, limits: tuple[int, int] | None = ...) -> tuple[int, int]: ...
205205
def cpu_num(self) -> int: ...

stubs/psutil/psutil/_common.pyi

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import enum
22
import io
3+
import sys
34
import threading
45
from _typeshed import ConvertibleToFloat, FileDescriptorOrPath, Incomplete, StrOrBytesPath, SupportsWrite
6+
from collections import defaultdict
57
from collections.abc import Callable
68
from socket import AF_INET6 as AF_INET6, AddressFamily, SocketKind
79
from typing import BinaryIO, Final, NamedTuple, SupportsIndex, TypeVar, overload
@@ -213,9 +215,7 @@ class addr(NamedTuple):
213215

214216
conn_tmap: dict[str, tuple[list[AddressFamily], list[SocketKind]]]
215217

216-
class Error(Exception):
217-
msg: str
218-
def __init__(self, msg: str = ...) -> None: ...
218+
class Error(Exception): ...
219219

220220
class NoSuchProcess(Error):
221221
pid: int
@@ -242,6 +242,7 @@ class TimeoutExpired(Error):
242242

243243
_P = ParamSpec("_P")
244244
_R = TypeVar("_R")
245+
_T = TypeVar("_T")
245246

246247
def usage_percent(used: ConvertibleToFloat, total: float, round_: SupportsIndex | None = None) -> float: ...
247248

@@ -257,32 +258,64 @@ def parse_environ_block(data: str) -> dict[str, str]: ...
257258
def sockfam_to_enum(num: int) -> AddressFamily: ...
258259
def socktype_to_enum(num: int) -> SocketKind: ...
259260
@overload
260-
def conn_to_ntuple(fd: int, fam: int, type_: int, laddr, raddr, status: str, status_map, pid: int) -> sconn: ...
261+
def conn_to_ntuple(
262+
fd: int,
263+
fam: int,
264+
type_: int,
265+
laddr: addr | tuple[str, int] | tuple[()],
266+
raddr: addr | tuple[str, int] | tuple[()],
267+
status: int | str,
268+
status_map: dict[int, str] | dict[str, str],
269+
pid: int,
270+
) -> sconn: ...
261271
@overload
262-
def conn_to_ntuple(fd: int, fam: int, type_: int, laddr, raddr, status: str, status_map, pid: None = None) -> pconn: ...
272+
def conn_to_ntuple(
273+
fd: int,
274+
fam: int,
275+
type_: int,
276+
laddr: addr | tuple[str, int] | tuple[()],
277+
raddr: addr | tuple[str, int] | tuple[()],
278+
status: int | str,
279+
status_map: dict[int, str] | dict[str, str],
280+
pid: None = None,
281+
) -> pconn: ...
263282
def deprecated_method(replacement: str) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]: ...
264283

265284
class _WrapNumbers:
266285
lock: threading.Lock
267-
cache: dict[Incomplete, Incomplete]
268-
reminders: dict[Incomplete, Incomplete]
269-
reminder_keys: dict[Incomplete, Incomplete]
286+
cache: dict[str, dict[str, tuple[int, ...]]]
287+
reminders: dict[str, defaultdict[Incomplete, int]]
288+
reminder_keys: dict[str, defaultdict[Incomplete, set[Incomplete]]]
270289
def __init__(self) -> None: ...
271-
def run(self, input_dict, name): ...
272-
def cache_clear(self, name=None) -> None: ...
273-
def cache_info(self) -> tuple[dict[Incomplete, Incomplete], dict[Incomplete, Incomplete], dict[Incomplete, Incomplete]]: ...
274-
275-
def wrap_numbers(input_dict, name: str): ...
290+
def run(self, input_dict: dict[str, tuple[int, ...]], name: str) -> dict[str, tuple[int, ...]]: ...
291+
def cache_clear(self, name: str | None = None) -> None: ...
292+
def cache_info(
293+
self,
294+
) -> tuple[
295+
dict[str, dict[str, tuple[int, ...]]],
296+
dict[str, defaultdict[Incomplete, int]],
297+
dict[str, defaultdict[Incomplete, set[Incomplete]]],
298+
]: ...
299+
300+
def wrap_numbers(input_dict: dict[str, tuple[int, ...]], name: str) -> dict[str, tuple[int, ...]]: ...
276301
def open_binary(fname: FileDescriptorOrPath) -> BinaryIO: ...
277302
def open_text(fname: FileDescriptorOrPath) -> io.TextIOWrapper: ...
278-
def cat(fname: FileDescriptorOrPath, fallback=..., _open=...): ...
279-
def bcat(fname: FileDescriptorOrPath, fallback=...): ...
303+
@overload
304+
def cat(fname: FileDescriptorOrPath, _open: Callable[[FileDescriptorOrPath], io.TextIOWrapper] = ...) -> str: ...
305+
@overload
306+
def cat(
307+
fname: FileDescriptorOrPath, fallback: _T = ..., _open: Callable[[FileDescriptorOrPath], io.TextIOWrapper] = ...
308+
) -> str | _T: ...
309+
@overload
310+
def bcat(fname: FileDescriptorOrPath) -> str: ...
311+
@overload
312+
def bcat(fname: FileDescriptorOrPath, fallback: _T = ...) -> str | _T: ...
280313
def bytes2human(n: int, format: str = "%(value).1f%(symbol)s") -> str: ...
281314
def get_procfs_path() -> str: ...
282315
def decode(s: bytes) -> str: ...
283-
def term_supports_colors(file: SupportsWrite[str] = ...) -> bool: ...
316+
def term_supports_colors(file: SupportsWrite[str] = sys.stdout) -> bool: ...
284317
def hilite(s: str, color: str | None = None, bold: bool = False) -> str: ...
285-
def print_color(s: str, color: str | None = None, bold: bool = False, file: SupportsWrite[str] = ...) -> None: ...
318+
def print_color(s: str, color: str | None = None, bold: bool = False, file: SupportsWrite[str] = sys.stdout) -> None: ...
286319
def debug(msg: str | Exception) -> None: ...
287320

288321
__all__ = [

0 commit comments

Comments
 (0)