psutil icon indicating copy to clipboard operation
psutil copied to clipboard

add settable info property on psutil.Process, default to empty dict

Open ringohoffman opened this issue 2 years ago • 4 comments

Summary

  • OS: linux, darwin
  • Bug fix: no
  • Type: new-api (adding an official property for psutil.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 info attribute is always set. I wonder if it's more correct for it to be an empty dict {} rather than None though.

Which I agree with.

Here is the typeshed update corresponding to this PR: https://github.com/python/typeshed/pull/10275

ringohoffman avatar Jun 07 '23 00:06 ringohoffman

@giampaolo Is there any plan to look at this? I would like to use it in a project of mine.

qthequartermasterman avatar Aug 21 '23 20:08 qthequartermasterman