diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2023-03-27 23:44:46 +0200 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2023-03-27 23:44:46 +0200 |
commit | f2216559ffa3e48dfccda331f8951a906a32c771 (patch) | |
tree | f0063119a8ccdde83e7124434bee4d06955a39e0 /psutil/_pslinux.py | |
parent | 64b4318bce1a2ba8dcc0b8f7cbaefeb029c12419 (diff) | |
download | psutil-f2216559ffa3e48dfccda331f8951a906a32c771.tar.gz |
When raising warning, always use stacklevel=2
B028: No explicit stacklevel argument found. The warn method from
the warnings module uses a stacklevel of 1 by default. This will
only show a stack trace for the line on which the warn method is
called. It is therefore recommended to use a stacklevel of 2 or
greater to provide more information to the user.
Signed-off-by: Giampaolo Rodola <g.rodola@gmail.com>
Diffstat (limited to 'psutil/_pslinux.py')
-rw-r--r-- | psutil/_pslinux.py | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 33ee1b14..11e62944 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -510,7 +510,7 @@ def virtual_memory(): msg = "%s memory stats couldn't be determined and %s set to 0" % ( ", ".join(missing_fields), "was" if len(missing_fields) == 1 else "were") - warnings.warn(msg, RuntimeWarning) + warnings.warn(msg, RuntimeWarning, stacklevel=2) return svmem(total, avail, percent, used, free, active, inactive, buffers, cached, shared, slab) @@ -544,7 +544,7 @@ def swap_memory(): # see https://github.com/giampaolo/psutil/issues/722 msg = "'sin' and 'sout' swap memory stats couldn't " \ "be determined and were set to 0 (%s)" % str(err) - warnings.warn(msg, RuntimeWarning) + warnings.warn(msg, RuntimeWarning, stacklevel=2) sin = sout = 0 else: with f: @@ -564,7 +564,7 @@ def swap_memory(): # https://github.com/giampaolo/psutil/issues/313 msg = "'sin' and 'sout' swap memory stats couldn't " \ "be determined and were set to 0" - warnings.warn(msg, RuntimeWarning) + warnings.warn(msg, RuntimeWarning, stacklevel=2) sin = sout = 0 return _common.sswap(total, used, free, percent, sin, sout) |