diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index caed859f8..5d5595feb 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -641,11 +641,10 @@ def cpu_count_cores(): except KeyError: pass current_info = {} - else: + elif line.startswith((b'physical id', b'cpu cores')): # ongoing section - if line.startswith((b'physical id', b'cpu cores')): - key, value = line.split(b'\t:', 1) - current_info[key] = int(value) + key, value = line.split(b'\t:', 1) + current_info[key] = int(value) result = sum(mapping.values()) return result or None # mimic os.cpu_count() diff --git a/psutil/tests/test_posix.py b/psutil/tests/test_posix.py index 1b8b76dc0..6c8ac7f49 100755 --- a/psutil/tests/test_posix.py +++ b/psutil/tests/test_posix.py @@ -55,11 +55,10 @@ def ps(fmt, pid=None): if pid is not None: cmd.extend(['-p', str(pid)]) + elif SUNOS or AIX: + cmd.append('-A') else: - if SUNOS or AIX: - cmd.append('-A') - else: - cmd.append('ax') + cmd.append('ax') if SUNOS: fmt = fmt.replace("start", "stime") diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 966797d7a..35432b1db 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -660,17 +660,16 @@ def test_memory_maps(self): data = f.read() if "%s (deleted)" % nt.path not in data: raise - else: + elif '64' not in os.path.basename(nt.path): # XXX - On Windows we have this strange behavior with # 64 bit dlls: they are visible via explorer but cannot # be accessed via os.stat() (wtf?). - if '64' not in os.path.basename(nt.path): - try: - st = os.stat(nt.path) - except FileNotFoundError: - pass - else: - assert stat.S_ISREG(st.st_mode), nt.path + try: + st = os.stat(nt.path) + except FileNotFoundError: + pass + else: + assert stat.S_ISREG(st.st_mode), nt.path for nt in ext_maps: for fname in nt._fields: value = getattr(nt, fname) diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index a2c4ac64e..1e814b1e8 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -963,9 +963,8 @@ def test_sensors_battery(self): psutil.POWER_TIME_UNLIMITED, }: assert ret.secsleft >= 0 - else: - if ret.secsleft == psutil.POWER_TIME_UNLIMITED: - assert ret.power_plugged + elif ret.secsleft == psutil.POWER_TIME_UNLIMITED: + assert ret.power_plugged assert isinstance(ret.power_plugged, bool) @pytest.mark.skipif(not HAS_SENSORS_FANS, reason="not supported") diff --git a/pyproject.toml b/pyproject.toml index a835733b2..04c4b291a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -70,7 +70,6 @@ ignore = [ "PLR1702", # Too many nested blocks (x > y) "PLR1704", # Redefining argument with the local name `type_` "PLR2004", # Magic value used in comparison, consider replacing X with a constant variable - "PLR5501", # Use `elif` instead of `else` then `if`, to reduce indentation "PLR6301", # Method `x` could be a function, class method, or static method "PLW0603", # Using the global statement to update `lineno` is discouraged "PLW1514", # `open` in text mode without explicit `encoding` argument