Make pylint happy

- fix super-with-arguments
- fix various other issues
- review broad-except and ignore where appropriate
This commit is contained in:
Marek Marczykowski-Górecki 2020-08-23 02:53:36 +02:00
parent a2f8ba9418
commit 6f465fc674
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
20 changed files with 49 additions and 49 deletions

View File

@ -31,7 +31,7 @@ from . import ui_about # pylint: disable=no-name-in-module
# pylint: disable=too-few-public-methods
class AboutDialog(ui_about.Ui_AboutDialog, QDialog):
def __init__(self):
super(AboutDialog, self).__init__()
super().__init__()
self.setupUi(self)

View File

@ -28,7 +28,7 @@ from qubesadmin import exc
# pylint: disable=too-few-public-methods
class AppListWidgetItem(QtWidgets.QListWidgetItem):
def __init__(self, name, ident, tooltip=None, parent=None):
super(AppListWidgetItem, self).__init__(name, parent)
super().__init__(name, parent)
additional_description = ".desktop filename: " + str(ident)
if not tooltip:
tooltip = additional_description

View File

@ -70,7 +70,7 @@ class BackupThread(QtCore.QThread):
class BackupVMsWindow(ui_backupdlg.Ui_Backup, QtWidgets.QWizard):
def __init__(self, qt_app, qubes_app, dispatcher, parent=None):
super(BackupVMsWindow, self).__init__(parent)
super().__init__(parent)
self.qt_app = qt_app
self.qubes_app = qubes_app

View File

@ -101,7 +101,7 @@ def select_path_button_clicked(dialog, select_file=False, read_only=False):
dialog.tr("Unexpected characters in path!"),
dialog.tr("Backup path can only contain the following "
"special characters: /:.,_+=() -"))
except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
QtWidgets.QMessageBox.warning(
dialog,
dialog.tr("Failed to select path!"),

View File

@ -30,7 +30,7 @@ from qubesadmin import exc
class VMBootFromDeviceWindow(ui_bootfromdevice.Ui_BootDialog,
QtWidgets.QDialog):
def __init__(self, vm, qapp, qubesapp=None, parent=None):
super(VMBootFromDeviceWindow, self).__init__(parent)
super().__init__(parent)
self.vm = vm
self.qapp = qapp

View File

@ -38,7 +38,7 @@ from .ui_clonevmdlg import Ui_CloneVMDlg # pylint: disable=import-error
class CloneVMDlg(QtWidgets.QDialog, Ui_CloneVMDlg):
def __init__(self, qtapp, app, parent=None, src_vm=None):
super(CloneVMDlg, self).__init__(parent)
super().__init__(parent)
self.setupUi(self)
self.qtapp = qtapp

View File

@ -56,7 +56,7 @@ class RemoveVMThread(QubesThread):
# pylint: disable=too-few-public-methods
class CloneVMThread(QubesThread):
def __init__(self, vm, dst_name, pool=None, label=None):
super(CloneVMThread, self).__init__(vm)
super().__init__(vm)
self.dst_name = dst_name
self.pool = pool
self.label = label

View File

@ -87,7 +87,7 @@ class CreateVMThread(QtCore.QThread):
class NewVmDlg(QtWidgets.QDialog, Ui_NewVMDlg):
def __init__(self, qtapp, app, parent=None):
super(NewVmDlg, self).__init__(parent)
super().__init__(parent)
self.setupUi(self)
self.qtapp = qtapp

View File

@ -23,7 +23,7 @@ from PyQt5 import QtWidgets # pylint: disable=import-error
class PCIDeviceListWindow(ui_devicelist.Ui_Dialog, QtWidgets.QDialog):
def __init__(self, vm, qapp, dev_list, no_strict_reset_list, parent=None):
super(PCIDeviceListWindow, self).__init__(parent)
super().__init__(parent)
self.vm = vm
self.qapp = qapp

View File

@ -33,7 +33,7 @@ class FirewallModifiedOutsideError(ValueError):
class NewFwRuleDlg(QtWidgets.QDialog, ui_newfwruledlg.Ui_NewFwRuleDlg):
def __init__(self, parent=None):
super(NewFwRuleDlg, self).__init__(parent)
super().__init__(parent)
self.setupUi(self)
self.set_ok_state(False)

View File

@ -50,12 +50,12 @@ def _run_qrexec_repo(service, arg=''):
env=env
)
if p.stderr:
raise RuntimeError(
raise exc.QubesException(
QtCore.QCoreApplication.translate(
"GlobalSettings", 'qrexec call stderr was not empty'),
{'stderr': p.stderr.decode('utf-8')})
if p.returncode != 0:
raise RuntimeError(
raise exc.QubesException(
QtCore.QCoreApplication.translate(
"GlobalSettings",
'qrexec call exited with non-zero return code'),
@ -67,7 +67,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
QtWidgets.QDialog):
def __init__(self, app, qubes_app, parent=None):
super(GlobalSettingsWindow, self).__init__(parent)
super().__init__(parent)
self.app = app
self.qubes_app = qubes_app
@ -287,7 +287,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
else:
try:
self.vm.features[feature] = widget.currentData()
except exc.QubesDaemonAccessError as ex:
except exc.QubesDaemonAccessError:
self.errors.append(
"Failed to set {} due to insufficient "
"permissions".format(feature))
@ -309,7 +309,8 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
try:
self.qmemman_config = ConfigParser()
self.vm_min_mem_val = '200MiB' # str(qmemman_algo.MIN_PREFMEM)
self.dom0_mem_boost_val = '350MiB' # str(qmemman_algo.DOM0_MEM_BOOST)
# str(qmemman_algo.DOM0_MEM_BOOST)
self.dom0_mem_boost_val = '350MiB'
self.qmemman_config.read(qmemman_config_path)
if self.qmemman_config.has_section('global'):
@ -360,7 +361,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
qmemman_config_file = open(qmemman_config_path, 'a')
self.qmemman_config.write(qmemman_config_file)
qmemman_config_file.close()
except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
self.errors.append(
"Failed to set memory settings due to {}".format(
str(ex)))
@ -380,7 +381,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
try:
qmemman_config_file = open(qmemman_config_path, 'r')
except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
self.errors.append(
"Failed to set memory settings due to {}".format(
str(ex)))
@ -405,7 +406,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
qmemman_config_file = open(qmemman_config_path, 'w')
qmemman_config_file.writelines(config_lines)
qmemman_config_file.close()
except Exception as ex:
except Exception as ex: # pylint: disable=broad-except
self.errors.append(
"Failed to set memory settings due to {}".format(
str(ex)))
@ -435,7 +436,7 @@ class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
dct = repos[lst[0]] = dict()
dct['prettyname'] = lst[1]
dct['enabled'] = lst[2] == 'enabled'
except Exception as ex:
except exc.QubesException:
self.dom0_updates_repo.setEnabled(False)
self.itl_tmpl_updates_repo.setEnabled(False)
self.comm_tmpl_updates_repo.setEnabled(False)

View File

@ -30,7 +30,7 @@ class InformationNotesDialog(ui_informationnotes.Ui_InformationNotesDialog,
QDialog):
# pylint: disable=too-few-public-methods
def __init__(self):
super(InformationNotesDialog, self).__init__()
super().__init__()
self.setupUi(self)
details = subprocess.check_output(

View File

@ -36,7 +36,7 @@ class LogDialog(ui_logdlg.Ui_LogDialog, QtWidgets.QDialog):
# pylint: disable=too-few-public-methods
def __init__(self, app, log_path, parent=None):
super(LogDialog, self).__init__(parent)
super().__init__(parent)
self.app = app
self.log_path = log_path

View File

@ -10,7 +10,7 @@ class MultiSelectWidget(
itemsRemoved = QtCore.pyqtSignal(list)
def __init__(self, parent=None):
super(MultiSelectWidget, self).__init__(parent)
super().__init__(parent)
self.setupUi(self)
self.add_selected_button.clicked.connect(self.add_selected)
self.add_all_button.clicked.connect(self.add_all)

View File

@ -58,16 +58,16 @@ from . import clone_vm
class SearchBox(QLineEdit):
def __init__(self, parent=None):
super(SearchBox, self).__init__(parent)
super().__init__(parent)
self.focusing = False
def focusInEvent(self, e): # pylint: disable=invalid-name
super(SearchBox, self).focusInEvent(e)
super().focusInEvent(e)
self.selectAll()
self.focusing = True
def mousePressEvent(self, e): # pylint: disable=invalid-name
super(SearchBox, self).mousePressEvent(e)
super().mousePressEvent(e)
if self.focusing:
self.selectAll()
self.focusing = False
@ -78,7 +78,7 @@ icon_size = QSize(22, 22)
class StateIconDelegate(QStyledItemDelegate):
lastIndex = None
def __init__(self):
super(StateIconDelegate, self).__init__()
super().__init__()
self.stateIcons = {
"Running" : QIcon(":/on.png"),
"Paused" : QIcon(":/paused.png"),
@ -104,7 +104,7 @@ class StateIconDelegate(QStyledItemDelegate):
}
def sizeHint(self, option, index):
hint = super(StateIconDelegate, self).sizeHint(option, index)
hint = super().sizeHint(option, index)
option = QStyleOptionViewItem(option)
option.features |= option.HasDecoration
widget = option.widget
@ -153,7 +153,7 @@ class StateIconDelegate(QStyledItemDelegate):
def helpEvent(self, event, view, option, index):
if event.type() != QEvent.ToolTip:
return super(StateIconDelegate, self).helpEvent(event, view,
return super().helpEvent(event, view,
option, index)
option = QStyleOptionViewItem(option)
widget = option.widget
@ -222,10 +222,9 @@ class VmInfo():
self.state['outdated'] = "to-be-outdated"
else:
try:
for vol in self.vm.volumes.values():
if vol.is_outdated():
self.state['outdated'] = "outdated"
break
if any(vol.is_outdated()
for vol in self.vm.volumes.values()):
self.state['outdated'] = "outdated"
except exc.QubesDaemonAccessError:
pass
@ -612,7 +611,7 @@ class UpdateVMThread(common_threads.QubesThread):
# pylint: disable=too-few-public-methods
class RunCommandThread(common_threads.QubesThread):
def __init__(self, vm, command_to_run):
super(RunCommandThread, self).__init__(vm)
super().__init__(vm)
self.command_to_run = command_to_run
def run(self):
@ -638,7 +637,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
settings_loaded = False
def __init__(self, qt_app, qubes_app, dispatcher, _parent=None):
super(VmManagerWindow, self).__init__()
super().__init__()
self.setupUi(self)
self.manager_settings = QSettings(self)
@ -816,7 +815,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow):
def keyPressEvent(self, event): # pylint: disable=invalid-name
if event.key() == Qt.Key_Escape:
self.searchbox.clear()
super(VmManagerWindow, self).keyPressEvent(event)
super().keyPressEvent(event)
def clear_threads(self):
for thread in self.threads_list:

View File

@ -28,7 +28,7 @@ from . import ui_releasenotes # pylint: disable=no-name-in-module
class ReleaseNotesDialog(ui_releasenotes.Ui_ReleaseNotesDialog, QDialog):
# pylint: disable=too-few-public-methods
def __init__(self):
super(ReleaseNotesDialog, self).__init__()
super().__init__()
self.setupUi(self)

View File

@ -70,7 +70,7 @@ class RestoreThread(QtCore.QThread):
class RestoreVMsWindow(ui_restoredlg.Ui_Restore, QtWidgets.QWizard):
def __init__(self, qt_app, qubes_app, parent=None):
super(RestoreVMsWindow, self).__init__(parent)
super().__init__(parent)
self.qt_app = qt_app
self.qubes_app = qubes_app
@ -122,7 +122,7 @@ class RestoreVMsWindow(ui_restoredlg.Ui_Restore, QtWidgets.QWizard):
if self.page(p_int) is self.select_vms_page:
self.vms_to_restore = None
else:
super(RestoreVMsWindow, self).cleanupPage(p_int)
super().cleanupPage(p_int)
def __fill_vms_list__(self):
if self.vms_to_restore is not None:

View File

@ -48,7 +48,7 @@ from . import ui_settingsdlg # pylint: disable=no-name-in-module
# pylint: disable=too-few-public-methods
class RenameVMThread(common_threads.QubesThread):
def __init__(self, vm, new_vm_name, dependencies):
super(RenameVMThread, self).__init__(vm)
super().__init__(vm)
self.new_vm_name = new_vm_name
self.dependencies = dependencies
@ -88,7 +88,7 @@ class RenameVMThread(common_threads.QubesThread):
# pylint: disable=too-few-public-methods
class RefreshAppsVMThread(common_threads.QubesThread):
def __init__(self, vm, button):
super(RefreshAppsVMThread, self).__init__(vm)
super().__init__(vm)
self.button = button
def run(self):
@ -129,7 +129,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
def __init__(self, vm, init_page="basic", qapp=None, qubesapp=None,
parent=None):
super(VMSettingsWindow, self).__init__(parent)
super().__init__(parent)
self.vm = vm
self.qapp = qapp
@ -251,7 +251,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
if event.key() == QtCore.Qt.Key_Enter \
or event.key() == QtCore.Qt.Key_Return:
return
super(VMSettingsWindow, self).keyPressEvent(event)
super().keyPressEvent(event)
def accept(self):
self.save_and_apply()
@ -1096,7 +1096,7 @@ class VMSettingsWindow(ui_settingsdlg.Ui_SettingsDialog, QtWidgets.QDialog):
# pylint: disable=too-few-public-methods
class DevListWidgetItem(QtWidgets.QListWidgetItem):
def __init__(self, dev, unknown=False, parent=None):
super(DevListWidgetItem, self).__init__(parent)
super().__init__(parent)
name = dev.ident.replace('_', ":") + ' ' + dev.description
if unknown:
name += ' (unknown)'

View File

@ -35,7 +35,7 @@ class TemplateManagerWindow(
def __init__(self, qt_app, qubes_app, dispatcher, parent=None):
# pylint: disable=unused-argument
super(TemplateManagerWindow, self).__init__()
super().__init__()
self.setupUi(self)
self.qubes_app = qubes_app
@ -244,7 +244,7 @@ class TemplateManagerWindow(
class VMNameItem(QtWidgets.QTableWidgetItem):
# pylint: disable=too-few-public-methods
def __init__(self, vm):
super(VMNameItem, self).__init__()
super().__init__()
self.vm = vm
self.setText(self.vm.name)
@ -253,7 +253,7 @@ class VMNameItem(QtWidgets.QTableWidgetItem):
class StatusItem(QtWidgets.QTableWidgetItem):
def __init__(self, vm):
super(StatusItem, self).__init__()
super().__init__()
self.vm = vm
self.state = None
@ -278,7 +278,7 @@ class StatusItem(QtWidgets.QTableWidgetItem):
class CurrentTemplateItem(QtWidgets.QTableWidgetItem):
# pylint: disable=too-few-public-methods
def __init__(self, vm):
super(CurrentTemplateItem, self).__init__()
super().__init__()
self.vm = vm
self.setText(self.vm.template.name)
@ -291,7 +291,7 @@ class CurrentTemplateItem(QtWidgets.QTableWidgetItem):
class NewTemplateItem(QtWidgets.QComboBox):
def __init__(self, vm, templates, table_widget):
super(NewTemplateItem, self).__init__()
super().__init__()
self.vm = vm
self.table_widget = table_widget
self.changed = False

View File

@ -77,7 +77,7 @@ class SizeSpinBox(QtWidgets.QSpinBox):
"""A SpinBox subclass with extended handling for sizes in MB and GB"""
# pylint: disable=invalid-name, no-self-use
def __init__(self, *args, **kwargs):
super(SizeSpinBox, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.pattern = r'(\d+\.?\d?) ?(GB|MB)'
self.regex = re.compile(self.pattern)