diff --git a/Makefile b/Makefile index 0406fb6da..60d82336e 100644 --- a/Makefile +++ b/Makefile @@ -233,7 +233,7 @@ fix-black: @git ls-files '*.py' | xargs $(PYTHON) -m black fix-ruff: - @git ls-files '*.py' | xargs $(PYTHON) -m ruff check --no-cache --fix + @git ls-files '*.py' | xargs $(PYTHON) -m ruff check --no-cache --fix $(ARGS) fix-unittests: ## Fix unittest idioms. @git ls-files '*test_*.py' | xargs $(PYTHON) -m teyit --show-stats diff --git a/psutil/_common.py b/psutil/_common.py index c1ff18d1f..9fd7b0cfb 100644 --- a/psutil/_common.py +++ b/psutil/_common.py @@ -980,7 +980,7 @@ def debug(msg): if PSUTIL_DEBUG: import inspect - fname, lineno, _, lines, index = inspect.getframeinfo( + fname, lineno, _, _lines, _index = inspect.getframeinfo( inspect.currentframe().f_back ) if isinstance(msg, Exception): diff --git a/psutil/_psaix.py b/psutil/_psaix.py index 65ce3374f..f48425eb8 100644 --- a/psutil/_psaix.py +++ b/psutil/_psaix.py @@ -105,7 +105,7 @@ def virtual_memory(): - total, avail, free, pinned, inuse = cext.virtual_mem() + total, avail, free, _pinned, inuse = cext.virtual_mem() percent = usage_percent((total - avail), total, round_=1) return svmem(total, avail, percent, inuse, free) diff --git a/psutil/_psbsd.py b/psutil/_psbsd.py index b11b81c35..4d49cf98b 100644 --- a/psutil/_psbsd.py +++ b/psutil/_psbsd.py @@ -321,7 +321,7 @@ def cpu_stats(): if FREEBSD: # Note: the C ext is returning some metrics we are not exposing: # traps. - ctxsw, intrs, soft_intrs, syscalls, traps = cext.cpu_stats() + ctxsw, intrs, soft_intrs, syscalls, _traps = cext.cpu_stats() elif NETBSD: # XXX # Note about intrs: the C extension returns 0. intrs @@ -332,7 +332,7 @@ def cpu_stats(): # # Note: the C ext is returning some metrics we are not exposing: # traps, faults and forks. - ctxsw, intrs, soft_intrs, syscalls, traps, faults, forks = ( + ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = ( cext.cpu_stats() ) with open('/proc/stat', 'rb') as f: @@ -342,7 +342,7 @@ def cpu_stats(): elif OPENBSD: # Note: the C ext is returning some metrics we are not exposing: # traps, faults and forks. - ctxsw, intrs, soft_intrs, syscalls, traps, faults, forks = ( + ctxsw, intrs, soft_intrs, syscalls, _traps, _faults, _forks = ( cext.cpu_stats() ) return _common.scpustats(ctxsw, intrs, soft_intrs, syscalls) diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 0ee134799..167183881 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -1080,25 +1080,25 @@ def net_io_counters(): name = line[:colon].strip() fields = line[colon + 1 :].strip().split() - # in ( + # in bytes_recv, packets_recv, errin, dropin, - fifoin, # unused - framein, # unused - compressedin, # unused - multicastin, # unused + _fifoin, # unused + _framein, # unused + _compressedin, # unused + _multicastin, # unused # out bytes_sent, packets_sent, errout, dropout, - fifoout, # unused - collisionsout, # unused - carrierout, # unused - compressedout, + _fifoout, # unused + _collisionsout, # unused + _carrierout, # unused + _compressedout, # unused ) = map(int, fields) retdict[name] = ( @@ -2091,9 +2091,9 @@ def get_blocks(lines, current_block): for header, data in get_blocks(lines, current_block): hfields = header.split(None, 5) try: - addr, perms, offset, dev, inode, path = hfields + addr, perms, _offset, _dev, _inode, path = hfields except ValueError: - addr, perms, offset, dev, inode, path = hfields + [''] + addr, perms, _offset, _dev, _inode, path = hfields + [''] if not path: path = '[anon]' else: diff --git a/psutil/_psosx.py b/psutil/_psosx.py index 106709467..41263fd73 100644 --- a/psutil/_psosx.py +++ b/psutil/_psosx.py @@ -165,7 +165,7 @@ def cpu_count_cores(): def cpu_stats(): - ctx_switches, interrupts, soft_interrupts, syscalls, traps = ( + ctx_switches, interrupts, soft_interrupts, syscalls, _traps = ( cext.cpu_stats() ) return _common.scpustats( diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index 6112728b1..1c0b96e9e 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -209,7 +209,7 @@ def cpu_count_cores(): def cpu_stats(): """Return various CPU stats as a named tuple.""" - ctx_switches, interrupts, syscalls, traps = cext.cpu_stats() + ctx_switches, interrupts, syscalls, _traps = cext.cpu_stats() soft_interrupts = 0 return _common.scpustats( ctx_switches, interrupts, soft_interrupts, syscalls diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index babb8e82e..0ba511b90 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -238,7 +238,7 @@ def getpagesize(): def virtual_memory(): """System virtual memory as a namedtuple.""" mem = cext.virtual_mem() - totphys, availphys, totsys, availsys = mem + totphys, availphys, _totsys, _availsys = mem total = totphys avail = availphys free = availphys @@ -337,7 +337,7 @@ def cpu_count_cores(): def cpu_stats(): """Return CPU statistics.""" - ctx_switches, interrupts, dpcs, syscalls = cext.cpu_stats() + ctx_switches, interrupts, _dpcs, syscalls = cext.cpu_stats() soft_interrupts = 0 return _common.scpustats( ctx_switches, interrupts, soft_interrupts, syscalls @@ -986,7 +986,7 @@ def create_time(self): # Note: proc_times() not put under oneshot() 'cause create_time() # is already cached by the main Process class. try: - user, system, created = cext.proc_times(self.pid) + _user, _system, created = cext.proc_times(self.pid) return created except OSError as err: if is_permission_err(err): @@ -1010,7 +1010,7 @@ def threads(self): @wrap_exceptions def cpu_times(self): try: - user, system, created = cext.proc_times(self.pid) + user, system, _created = cext.proc_times(self.pid) except OSError as err: if not is_permission_err(err): raise diff --git a/psutil/tests/runner.py b/psutil/tests/runner.py index a054e4817..3b28b64f1 100755 --- a/psutil/tests/runner.py +++ b/psutil/tests/runner.py @@ -256,7 +256,7 @@ def run(self, suite): # At this point we should have N zombies (the workers), which # will disappear with wait(). orphans = psutil.Process().children() - gone, alive = psutil.wait_procs(orphans, timeout=1) + _gone, alive = psutil.wait_procs(orphans, timeout=1) if alive: cprint("alive processes %s" % alive, "red") reap_children() diff --git a/psutil/tests/test_bsd.py b/psutil/tests/test_bsd.py index a714632dc..8512b4f9e 100755 --- a/psutil/tests/test_bsd.py +++ b/psutil/tests/test_bsd.py @@ -171,7 +171,7 @@ def test_memory_maps(self): while lines: line = lines.pop() fields = line.split() - _, start, stop, perms, res = fields[:5] + _, start, stop, _perms, res = fields[:5] map = maps.pop() self.assertEqual("%s-%s" % (start, stop), map.addr) self.assertEqual(int(res), map.rss) @@ -416,19 +416,19 @@ def test_cpu_stats_syscalls(self): # --- swap memory def test_swapmem_free(self): - total, used, free = self.parse_swapinfo() + _total, _used, free = self.parse_swapinfo() self.assertAlmostEqual( psutil.swap_memory().free, free, delta=TOLERANCE_SYS_MEM ) def test_swapmem_used(self): - total, used, free = self.parse_swapinfo() + _total, used, _free = self.parse_swapinfo() self.assertAlmostEqual( psutil.swap_memory().used, used, delta=TOLERANCE_SYS_MEM ) def test_swapmem_total(self): - total, used, free = self.parse_swapinfo() + total, _used, _free = self.parse_swapinfo() self.assertAlmostEqual( psutil.swap_memory().total, total, delta=TOLERANCE_SYS_MEM ) @@ -447,7 +447,7 @@ def test_boot_time(self): @unittest.skipIf(not HAS_BATTERY, "no battery") def test_sensors_battery(self): def secs2hours(secs): - m, s = divmod(secs, 60) + m, _s = divmod(secs, 60) h, m = divmod(m, 60) return "%d:%02d" % (h, m) diff --git a/psutil/tests/test_process.py b/psutil/tests/test_process.py index 307d3dfa9..0cae26d7e 100755 --- a/psutil/tests/test_process.py +++ b/psutil/tests/test_process.py @@ -808,7 +808,7 @@ def test_prog_w_funky_name(self): @unittest.skipIf(not POSIX, 'POSIX only') def test_uids(self): p = psutil.Process() - real, effective, saved = p.uids() + real, effective, _saved = p.uids() # os.getuid() refers to "real" uid self.assertEqual(real, os.getuid()) # os.geteuid() refers to "effective" uid @@ -822,7 +822,7 @@ def test_uids(self): @unittest.skipIf(not POSIX, 'POSIX only') def test_gids(self): p = psutil.Process() - real, effective, saved = p.gids() + real, effective, _saved = p.gids() # os.getuid() refers to "real" uid self.assertEqual(real, os.getgid()) # os.geteuid() refers to "effective" uid diff --git a/psutil/tests/test_process_all.py b/psutil/tests/test_process_all.py index 7c6ce7808..d1f476bb5 100755 --- a/psutil/tests/test_process_all.py +++ b/psutil/tests/test_process_all.py @@ -522,7 +522,7 @@ def check(pid): psutil.Process(pid) if not WINDOWS: # see docstring self.assertNotIn(pid, psutil.pids()) - except (psutil.Error, AssertionError) as err: + except (psutil.Error, AssertionError): x -= 1 if x == 0: raise diff --git a/psutil/tests/test_system.py b/psutil/tests/test_system.py index 32ac62cbe..554fbffb2 100755 --- a/psutil/tests/test_system.py +++ b/psutil/tests/test_system.py @@ -845,7 +845,7 @@ def test_net_if_addrs(self): 0, socket.AI_PASSIVE, )[0] - af, socktype, proto, canonname, sa = info + af, socktype, proto, _canonname, sa = info s = socket.socket(af, socktype, proto) with contextlib.closing(s): s.bind(sa) diff --git a/psutil/tests/test_testutils.py b/psutil/tests/test_testutils.py index 17cc9eb08..1a18b65a8 100755 --- a/psutil/tests/test_testutils.py +++ b/psutil/tests/test_testutils.py @@ -240,7 +240,7 @@ def test_spawn_children_pair(self): @unittest.skipIf(not POSIX, "POSIX only") def test_spawn_zombie(self): - parent, zombie = self.spawn_zombie() + _parent, zombie = self.spawn_zombie() self.assertEqual(zombie.status(), psutil.STATUS_ZOMBIE) def test_terminate(self): diff --git a/psutil/tests/test_windows.py b/psutil/tests/test_windows.py index 5983af70a..7778cf4a6 100755 --- a/psutil/tests/test_windows.py +++ b/psutil/tests/test_windows.py @@ -407,7 +407,7 @@ def test_special_pid(self): p.username() self.assertGreaterEqual(p.create_time(), 0.0) try: - rss, vms = p.memory_info()[:2] + rss, _vms = p.memory_info()[:2] except psutil.AccessDenied: # expected on Windows Vista and Windows 7 if platform.uname()[1] not in ('vista', 'win-7', 'win7'): diff --git a/pyproject.toml b/pyproject.toml index 99a9b44d5..b03392071 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,6 @@ ignore = [ "D", # pydocstyle "DTZ", # flake8-datetimez "ERA001", # Found commented-out code - "F841", # Local variable `parent` is assigned to but never used "FBT", # flake8-boolean-trap (makes zero sense) "FIX", # Line contains TODO / XXX / ..., consider resolving the issue "FLY", # flynt (PYTHON2.7 COMPAT) diff --git a/setup.py b/setup.py index 3c7900669..e3375004b 100755 --- a/setup.py +++ b/setup.py @@ -431,7 +431,7 @@ def get_sunos_update(): class bdist_wheel_abi3(bdist_wheel): def get_tag(self): - python, abi, plat = bdist_wheel.get_tag(self) + python, _abi, plat = bdist_wheel.get_tag(self) return python, "abi3", plat cmdclass["bdist_wheel"] = bdist_wheel_abi3