Skip to content

Conversation

emmanuel-ferdman
Copy link
Contributor

PR Summary

This PR adds typing support for the cache_clear method of psutil.process_iter. The fix replaces the function declaration with a _ProcessIterCallable Protocol that defines both the original callable signature and the new cache_clear() method, resolving mypy errors when accessing psutil.process_iter.cache_clear() while maintaining full backward compatibility with existing code.

Closes #14281.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>

This comment has been minimized.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks mostly good, a few specific notes below.

Generally regarding tests, we try to use a "less is more" approach in typeshed (as opposed to your typical unit tests in other projects), as the tests are fairly expensive, but are also often just repeating the type annotations, and many typical problems are already caught by tools like stubtest.

In this specific PR, it definitely makes sense to test that process_iter is still a callable, and that the clear_method() function exists as an attribute and is callable, but we don't need to the different argument permutations of process_iter(), and the last test just seems redundant with prior tests.

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau merged commit 8845352 into python:main Sep 30, 2025
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

psutil.process_iter.cache_clear not available
2 participants