Skip to content

Commit

Permalink
ruff: enable and fix 'unused variable' rule
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Jun 2, 2024
1 parent 5530985 commit 20be5ae
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psaix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions psutil/_psbsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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)
Expand Down
22 changes: 11 additions & 11 deletions psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = (
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion psutil/_psosx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion psutil/_pssunos.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions psutil/_pswindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions psutil/tests/test_bsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand All @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_process_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 20be5ae

Please sign in to comment.