Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions stubs/psutil/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ psutil._pssunos

# Test utilities
psutil.tests.*

# process_iter is enhanced with cache_clear method that's not detected by stubtest
psutil.process_iter
16 changes: 16 additions & 0 deletions stubs/psutil/@tests/test_cases/check_process_iter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Test cases for psutil.process_iter and its cache_clear method."""

from __future__ import annotations

import psutil

# Test that process_iter can be called as a function
for proc in psutil.process_iter():
break

# Test that process_iter has cache_clear method
psutil.process_iter.cache_clear()

# Test that cache_clear is callable
clear_method = psutil.process_iter.cache_clear
clear_method()
15 changes: 11 additions & 4 deletions stubs/psutil/psutil/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sys
from _typeshed import Incomplete
from collections.abc import Callable, Iterable, Iterator
from contextlib import AbstractContextManager
from typing import Any, Literal, overload
from typing import Any, Literal, Protocol, overload, type_check_only
from typing_extensions import Self, TypeAlias, deprecated

from psutil._common import (
Expand Down Expand Up @@ -234,11 +234,18 @@ class Popen(Process):
def __getattribute__(self, name: str) -> Any: ...
def __dir__(self) -> list[str]: ...

@type_check_only
class _ProcessIterCallable(Protocol):
def __call__(
self, attrs: list[str] | tuple[str, ...] | set[str] | frozenset[str] | None = None, ad_value=None
) -> Iterator[Process]: ...
def cache_clear(self) -> None: ...

def pids() -> list[int]: ...
def pid_exists(pid: int) -> bool: ...
def process_iter(
attrs: list[str] | tuple[str, ...] | set[str] | frozenset[str] | None = None, ad_value=None
) -> Iterator[Process]: ...

process_iter: _ProcessIterCallable

def wait_procs(
procs: Iterable[Process], timeout: float | None = None, callback: Callable[[Process], object] | None = None
) -> tuple[list[Process], list[Process]]: ...
Expand Down