You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Proposal to support Dict[str, Any] parameters for ad_value, so that each key provided in attrs may have a custom default value.
OS: Linux
Type: new-api
Description
As defined, as_dict(attrs=None, ad_value=None) only accepts a single default value for all keys provided in attrs. This means that it's not possible to have different default values for each key in attrs.
h4l7
changed the title
[Linux] Add support for Dict[str, Any] signature for ad_value parameter in psutil.Process.ad_dict(..)
[Linux] Add support for Dict[str, Any] signature for ad_value parameter in psutil.Process.as_dict(..)
Dec 10, 2023
Nope, it makes the API too complex both to use and to document.
Also, there would be no way to distinguish between "return {} for all APIs" vs. "here is a dict describing what each API should return", because they are both dicts.
If you want such a level of customization you are better off using the native APIs directly (cwd(), exe(), etc.), or write your own wrapper on top of them in way that is similar to as_dict().
Summary
Proposal to support
Dict[str, Any]
parameters forad_value
, so that each key provided inattrs
may have a custom default value.Description
As defined,
as_dict(attrs=None, ad_value=None)
only accepts a single default value for all keys provided inattrs
. This means that it's not possible to have different default values for each key inattrs
.For example, consider:
Relevant code snippet:
https://github.com/giampaolo/psutil/blob/master/psutil/__init__.py#L545
Function docs
https://psutil.readthedocs.io/en/latest/index.html#psutil.Process.as_dict
Thank you for your consideration.
The text was updated successfully, but these errors were encountered: