Skip to content

Commit

Permalink
refactor(lint): Work on PyLint rule W0612 (unused-variable)
Browse files Browse the repository at this point in the history
Thank you to Keith Bates (@dnerever) for this contribution.

Related to #1755 
---------

Co-authored-by: buhtz <c.buhtz@posteo.jp>
  • Loading branch information
dnerever and buhtz authored Aug 11, 2024
1 parent 6e2be6b commit 0ba4396
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1602,7 +1602,7 @@ def olderThan(self, time, value, unit):
- datetime.timedelta(weeks = value - 1)
elif unit <= self.MONTH:
firstDay = now.date() - datetime.timedelta(days = now.date().day + 1)
for i in range(value - 1):
for _ in range(value - 1):
if firstDay.month == 1:
firstDay = firstDay.replace(month = 12, year = firstDay.year - 1)
else:
Expand Down
2 changes: 1 addition & 1 deletion common/schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def is_cron_running():

with subprocess.Popen(['ps', '-eo', 'comm'], stdout=subprocess.PIPE) as ps:
try:
grep = subprocess.run(
subprocess.run(
['grep', '--ignore-case', 'cron'],
stdin=ps.stdout,
stdout=subprocess.PIPE,
Expand Down
6 changes: 3 additions & 3 deletions common/sshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ def maxArg():
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True)
out, err = proc.communicate()
err = proc.communicate()[1]

if err or proc.returncode:
logger.debug(f'rsync command returned error: {err}', self)
Expand Down Expand Up @@ -1057,7 +1057,7 @@ def sshKeyGen(keyfile):
stderr=subprocess.PIPE,
universal_newlines=True)

out, err = proc.communicate()
err = proc.communicate()[1]

if proc.returncode:
logger.error('Failed to create a new ssh-key: {}'.format(err))
Expand Down Expand Up @@ -1178,7 +1178,7 @@ def sshCopyId(
# backintime-askpass
universal_newlines=True)

out, err = proc.communicate()
err = proc.communicate()[1]

if proc.returncode:
logger.error('Failed to copy ssh-key "{}" to "{}@{}": [{}] {}'
Expand Down
2 changes: 1 addition & 1 deletion common/test/test_applicationinstance.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_non_existing_process(self):
self.assertTrue(self.app_instance.check())

def test_leftover_empty_lockfile(self):
with open(self.file_name, 'wt')as f:
with open(self.file_name, 'wt') as f:
pass
self.assertTrue(self.app_instance.check())

Expand Down
18 changes: 9 additions & 9 deletions common/test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,30 @@ def test_with_pylint(self):
'E0401', # import-error
'E0602', # undefined-variable
'E1101', # no-member
'W0311', # bad-indentation
'I0021', # useless-suppression
'W0123', # eval-used
'W0237', # arguments-renamed
'W0311', # bad-indentation
'W0404', # reimported
'W0611', # unused-import
# 'W0612', # unused-variable
'W0614', # unused-wildcard-import
'W0707', # raise-missing-from
'W1301', # unused-format-string-key
'W1401', # anomalous-backslash-in-string (invalid escape sequence)
'W1515', # forgotten-debug-statement
'W4902', # deprecated-method
'W4904', # deprecated-class
'R0201', # no-self-use
'R0202', # no-classmethod-decorator
'R0203', # no-staticmethod-decorator
'W0404', # reimported
'W4902', # deprecated-method
'W4904', # deprecated-class
'W0614', # unused-wildcard-import
'W0237', # arguments-renamed
'W0123', # eval-used
'W0707', # raise-missing-from

# Enable asap. This list is a selection of existing (not all!)
# problems currently existing in the BIT code base. Quite easy to fix
# because their count is low.
# 'R0801', # duplicate-code
# 'W0221', # arguments-differ
# 'W0603', # global-statement
# 'W0612', # unused-variable
]

cmd.append('--enable=' + ','.join(err_codes))
Expand Down
1 change: 0 additions & 1 deletion common/test/test_plugin_usercallback.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def _extract_callback_responses(cls, output):
callback_responses = []

for line in response_lines:
to_eval = line[line.index("'")+1:line.rindex("'")]

callback_responses.append(
literal_eval(line[line.index("'")+1:line.rindex("'")])
Expand Down
5 changes: 2 additions & 3 deletions common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import gzip
import locale
import gettext
from collections.abc import MutableSet
import hashlib
import ipaddress
import atexit
Expand Down Expand Up @@ -2704,7 +2703,7 @@ def stop(self):
return

# Get the pid from the pidfile
pid, procname = self.appInstance.readPidFile()
pid = self.appInstance.readPidFile()[0]

if not pid:
message = "pidfile %s does not exist. Daemon not running?\n"
Expand Down Expand Up @@ -2740,7 +2739,7 @@ def reload(self):
return

# Get the pid from the pidfile
pid, procname = self.appInstance.readPidFile()
pid = self.appInstance.readPidFile()[0]

if not pid:
message = "pidfile %s does not exist. Daemon not running?\n"
Expand Down
3 changes: 1 addition & 2 deletions qt/test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,9 @@ def test_with_pylint(self):
'E0401', # import-error
'E0602', # undefined-variable
'E1101', # no-member
'I0021', # useless-suppression
'W0311', # bad-indentation
'W0611', # unused-import
'I0021', # useless-suppression
# 'W0611', # unused-import
'W1301', # unused-format-string-key
'W1401', # anomalous-backslash-in-string (invalid escape sequence)
'W1515', # forgotten-debug-statement
Expand Down

0 comments on commit 0ba4396

Please sign in to comment.