psutil
psutil copied to clipboard
add settable info property on psutil.Process, default to empty dict
Summary
- OS: linux, darwin
- Bug fix: no
- Type: new-api (adding an official
propertyforpsutil.Process.info) - Related: https://github.com/python/typeshed/issues/10195, https://github.com/giampaolo/psutil/pull/2260
Motivation
This example from the docs raises type errors since info is not defined in the __init__:
https://psutil.readthedocs.io/en/latest/#psutil.process_iter:
import psutil
for proc in psutil.process_iter(['pid', 'name', 'username']):
print(proc.info) # Cannot access member "info" for type "Process"; Member "info" is unknown
Description
This PR is an alternate implementation of #10195, addressing @giampaolo's comment: https://github.com/giampaolo/psutil/pull/2260#issuecomment-1566821018
I suppose it's less surprising for the user if
infoattribute is always set. I wonder if it's more correct for it to be an empty dict{}rather thanNonethough.
Which I agree with.
Here is the typeshed update corresponding to this PR: https://github.com/python/typeshed/pull/10275
@giampaolo Is there any plan to look at this? I would like to use it in a project of mine.