Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 31 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,31 @@
"""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 (original behavior)
Comment thread
emmanuel-ferdman marked this conversation as resolved.
Outdated
for proc in psutil.process_iter():
break

for proc in psutil.process_iter(attrs=["pid", "name"]):
break

for proc in psutil.process_iter(attrs=["pid"], ad_value="N/A"):
break

# Test that process_iter has cache_clear method (new behavior)
Comment thread
emmanuel-ferdman marked this conversation as resolved.
Outdated
psutil.process_iter.cache_clear()

# Test that cache_clear is callable
clear_method = psutil.process_iter.cache_clear
clear_method()

# Test type annotations work correctly
from collections.abc import Iterator

processes: Iterator[psutil.Process] = psutil.process_iter()
processes_with_attrs: Iterator[psutil.Process] = psutil.process_iter(attrs=["pid"])

# Test that cache_clear returns None
psutil.process_iter.cache_clear() # Returns None, don't assign
14 changes: 10 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
from typing_extensions import Self, TypeAlias, deprecated

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

class _ProcessIterCallable(Protocol):
Comment thread
emmanuel-ferdman marked this conversation as resolved.
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
Loading