Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Enable and fix PyLint rules C0305 (trailing-newlines), C0324 (superfluous-parens), C0410 (multiple-imports), E0213 (no-self-argument) #1766

Merged
merged 4 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Back In Time

Version 1.4.4-dev (development of upcoming release)
* Build: Enable PyLint rules C0305 (trailing-newlines), C0324 (superfluous-parens), C0410 (multiple-imports), E0213 (no-self-argument)
* Feature: Warn if Cron is not running (#1747)
* Build: Activate PyLint error C0303 (trailing-whitespaces)
* Build: Activate PyLint error W0311 (bad-indentation)
Expand Down
6 changes: 4 additions & 2 deletions common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ def terminalSize():
"""
for fd in (sys.stdin, sys.stdout, sys.stderr):
try:
import fcntl, termios, struct
import fcntl
import termios
import struct
return [int(x) for x in struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234'))]
except:
except ImportError:
pass
return [24, 80]

Expand Down
2 changes: 1 addition & 1 deletion common/mount.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ def hash(self, s):
Returns:
str: hash of string ``s``
"""
return('%X' % (crc32(s.encode()) & 0xFFFFFFFF))
return '%X' % (crc32(s.encode()) & 0xFFFFFFFF)

def hashIdPath(self, hash_id = None):
"""
Expand Down
4 changes: 2 additions & 2 deletions common/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ def reloadHandler(self, signum, frame):
"""
time.sleep(2)
cfgPath = self.config._LOCAL_CONFIG_PATH
del(self.config)
del self.config
self.config = config.Config(cfgPath)
del(self.dbKeyring)
del self.dbKeyring
self.dbKeyring = {}
self.collectPasswords()

Expand Down
2 changes: 1 addition & 1 deletion common/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ def filterRsyncProgress(self, line):
pg.setStrValue('speed', m.group(3))
#pg.setStrValue('eta', m.group(4))
pg.save()
del(pg)
del pg
else:
ret.append(l)
return '\n'.join(ret)
Expand Down
2 changes: 1 addition & 1 deletion common/test/test_config_crontab.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def setUp(self):

self.config_fp = self._create_config_file(parent_path=self.temp_path)

def _create_config_file(cls, parent_path):
def _create_config_file(self, parent_path):
"""Minimal config file"""
cfg_content = inspect.cleandoc('''
config.version=6
Expand Down
9 changes: 4 additions & 5 deletions common/test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ def test_with_pylint(self):

# Explicit activate checks
err_codes = [
'C0305', # trailing-newlines
'C0324', # superfluous-parens
'C0410', # multiple-imports
'C0303', # trailing-whitespace
'E0100', # init-is-generator
'E0101', # return-in-init
'E0102', # function-redefined
'E0103', # not-in-loop
'E0106', # return-arg-in-generator
'E0213', # no-self-argument
'E0401', # import-error
'E0602', # undefined-variable
'E1101', # no-member
Expand All @@ -94,11 +98,6 @@ def test_with_pylint(self):
# Enable asap. This list is selection of existing (not all!)
# problems currently exiting in the BIT code base. Quit easy to fix
# because there count is low.
# 'C0304', # missing-final-newline
# 'C0305', # trailing-newlines
# 'C0324', # superfluous-parens
# 'C0410', # multiple-imports
# 'E0213', # no-self-argument
# 'R0201', # no-self-use
# 'R0202', # no-classmethod-decorator
# 'R0203', # no-staticmethod-decorator
Expand Down
2 changes: 1 addition & 1 deletion common/test/test_snapshotlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_filter(self):
self.assertEqual(line, logFilter.filter(line))
for line in (self.e, self.c, self.i, self.h):
self.assertIsNone(logFilter.filter(line))
for line in (self.n):
for line in self.n:
self.assertEqual(line, logFilter.filter(line)) # empty line stays empty line

class TestSnapshotLog(generic.SnapshotsTestCase):
Expand Down
19 changes: 10 additions & 9 deletions common/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,7 @@ def checkCommand(cmd):

return which(cmd) is not None


def which(cmd):
"""Get the fullpath of executable command ``cmd``.

Expand Down Expand Up @@ -1230,7 +1231,7 @@ def envLoad(f):
continue
if not key in list(env.keys()):
os.environ[key] = value
del(env_file)
del env_file


def envSave(f):
Expand Down Expand Up @@ -2200,7 +2201,7 @@ def _prepair(self):
sessionbus = dbus.SessionBus()
systembus = dbus.SystemBus()
except:
return((None, None))
return (None, None)
des = list(self.DBUS_SHUTDOWN.keys())
des.sort()
for de in des:
Expand All @@ -2214,31 +2215,31 @@ def _prepair(self):
bus = systembus
interface = bus.get_object(dbus_props['service'], dbus_props['objectPath'])
proxy = interface.get_dbus_method(dbus_props['method'], dbus_props['interface'])
return((proxy, dbus_props['arguments']))
return (proxy, dbus_props['arguments'])
except dbus.exceptions.DBusException:
continue
return((None, None))
return (None, None)

def canShutdown(self):
"""
Indicate if a valid dbus service is available to shutdown system.
"""
return(not self.proxy is None or self.is_root)
return not self.proxy is None or self.is_root

def askBeforeQuit(self):
"""
Indicate if ShutDown is ready to fire and so the application
shouldn't be closed.
"""
return(self.activate_shutdown and not self.started)
return self.activate_shutdown and not self.started

def shutdown(self):
"""
Run 'shutdown -h now' if we are root or
call the dbus proxy to start the shutdown.
"""
if not self.activate_shutdown:
return(False)
return False

if self.is_root:
self.started = True
Expand All @@ -2247,12 +2248,12 @@ def shutdown(self):
return proc.returncode

if self.proxy is None:
return(False)
return False

else:
self.started = True

return(self.proxy(*self.args))
return self.proxy(*self.args)

def unity7(self):
"""
Expand Down
4 changes: 2 additions & 2 deletions qt/messagebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def askPasswordDialog(parent, title, prompt, language_code, timeout):
password = dialog.textValue()
else:
password = ''
del(dialog)
del dialog

return(password)
return password

def info(text, title=None, widget_to_center_on=None):
"""Show a modal information message box.
Expand Down
1 change: 0 additions & 1 deletion qt/qttools.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,3 @@ def setCurrentProfileID(self, profileID):
if self.itemData(i) == profileID:
self.setCurrentIndex(i)
break

1 change: 0 additions & 1 deletion qt/qttools_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ def registerBackintimePath(*path):

if path not in sys.path:
sys.path.insert(0, path)

9 changes: 4 additions & 5 deletions qt/test/test_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ def test_with_pylint(self):

# Explicit activate checks
err_codes = [
'C0305', # trailing-newlines
'C0324', # superfluous-parens
'C0410', # multiple-imports
'C0303', # trailing-whitespace
'E0100', # init-is-generator
'E0101', # return-in-init
'E0102', # function-redefined
'E0103', # not-in-loop
'E0106', # return-arg-in-generator
'E0213', # no-self-argument
'E0401', # import-error
'E0602', # undefined-variable
'E1101', # no-member
Expand All @@ -95,11 +99,6 @@ def test_with_pylint(self):
# Enable asap. This list is selection of existing (not all!)
# problems currently exiting in the BIT code base. Quit easy to fix
# because there count is low.
# 'C0304', # missing-final-newline
# 'C0305', # trailing-newlines
# 'C0324', # superfluous-parens
# 'C0410', # multiple-imports
# 'E0213', # no-self-argument
# 'R0201', # no-self-use
# 'R0202', # no-classmethod-decorator
# 'R0203', # no-staticmethod-decorator
Expand Down