From fd445f5b938f7e93a7a32c2a83e5cc8690663755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 26 Sep 2024 04:48:45 +0200 Subject: [PATCH] pylint: deal with too-many-positional-arguments First of all, raise default warning level - many event handlers have standard 6 or 7 arguments. Then, adjust other cases, converting to keyword-only arguments for readability (they were used this way already anyway). This also revealed few places where DeviceAssignment was used incorrectly. (cherry picked from commit caf0dae01ca20ee9e2472cf21d7e6acba77fb741) Adjust for old devices API in release4.2 branch. --- .pylintrc | 2 ++ qubes/__init__.py | 2 +- qubes/backup.py | 1 + qubes/dochelpers.py | 2 +- qubes/storage/__init__.py | 2 +- qubes/storage/zfs.py | 1 + qubes/tests/api_admin.py | 8 ++++---- qubes/tests/vm/qubesvm.py | 6 ++++-- qubes/tools/__init__.py | 1 + qubes/vm/__init__.py | 2 +- qubes/vm/qubesvm.py | 5 +++-- 11 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.pylintrc b/.pylintrc index 2a180dce7..00a9b6dda 100644 --- a/.pylintrc +++ b/.pylintrc @@ -191,6 +191,8 @@ min-public-methods=2 # Maximum number of public methods for a class (see R0904). max-public-methods=100 +max-positional-arguments=7 + [EXCEPTIONS] diff --git a/qubes/__init__.py b/qubes/__init__.py index bf7f730a3..99685bb7a 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -189,7 +189,7 @@ class property: # pylint: disable=redefined-builtin,invalid-name # internal use only _NO_DEFAULT = object() - def __init__(self, name, setter=None, saver=None, type=None, + def __init__(self, name, setter=None, saver=None, type=None, *, default=_NO_DEFAULT, write_once=False, load_stage=2, order=0, save_via_ref=False, clone=True, doc=None): diff --git a/qubes/backup.py b/qubes/backup.py index 720cbaaf6..dac6df08d 100644 --- a/qubes/backup.py +++ b/qubes/backup.py @@ -88,6 +88,7 @@ class BackupHeader: int_options = ['version'] def __init__(self, + *, version=None, encrypted=None, compressed=None, diff --git a/qubes/dochelpers.py b/qubes/dochelpers.py index 6fab4de49..c9bb10daf 100644 --- a/qubes/dochelpers.py +++ b/qubes/dochelpers.py @@ -89,7 +89,7 @@ def ticket(name, rawtext, text, lineno, inliner, options=None, content=None): that called this function :param options: Directive options for customisation :param content: The directive content for customisation - """ # pylint: disable=unused-argument + """ # pylint: disable=unused-argument,too-many-positional-arguments if options is None: options = {} diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index b1464ab6a..07015754d 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -82,7 +82,7 @@ class Volume: #: for sparse volumes usage = 0 - def __init__(self, name, pool, vid, + def __init__(self, name, pool, vid, *, revisions_to_keep=0, rw=False, save_on_stop=False, size=0, snap_on_start=False, source=None, ephemeral=None, **kwargs): ''' Initialize a volume. diff --git a/qubes/storage/zfs.py b/qubes/storage/zfs.py index c0af567a7..a100d17fd 100644 --- a/qubes/storage/zfs.py +++ b/qubes/storage/zfs.py @@ -1803,6 +1803,7 @@ def __init__( name: str, pool: ZFSPool, vid: Vid, + *, revisions_to_keep: int = 1, rw: bool = False, save_on_stop: bool = False, diff --git a/qubes/tests/api_admin.py b/qubes/tests/api_admin.py index 0ab60b5cf..d3a1a72c5 100644 --- a/qubes/tests/api_admin.py +++ b/qubes/tests/api_admin.py @@ -2677,8 +2677,8 @@ def test_651_vm_device_set_persistent_false_unchanged(self): def test_652_vm_device_set_persistent_false(self): self.vm.add_handler('device-list:testclass', self.device_list_testclass) - assignment = qubes.devices.DeviceAssignment(self.vm, '1234', {}, - True) + assignment = qubes.devices.DeviceAssignment(self.vm, '1234', + persistent=True) self.loop.run_until_complete( self.vm.devices['testclass'].attach(assignment)) self.vm.add_handler('device-list-attached:testclass', @@ -2698,8 +2698,8 @@ def test_652_vm_device_set_persistent_false(self): def test_653_vm_device_set_persistent_true_unchanged(self): self.vm.add_handler('device-list:testclass', self.device_list_testclass) - assignment = qubes.devices.DeviceAssignment(self.vm, '1234', {}, - True) + assignment = qubes.devices.DeviceAssignment(self.vm, '1234', + persistent=True) self.loop.run_until_complete( self.vm.devices['testclass'].attach(assignment)) self.vm.add_handler('device-list-attached:testclass', diff --git a/qubes/tests/vm/qubesvm.py b/qubes/tests/vm/qubesvm.py index db0a8e0e6..6167db5f0 100644 --- a/qubes/tests/vm/qubesvm.py +++ b/qubes/tests/vm/qubesvm.py @@ -1481,7 +1481,8 @@ def test_600_libvirt_xml_hvm_cdrom_boot(self): self.app.vmm.offline_mode = False dev = qubes.devices.DeviceAssignment( dom0, 'sda', - {'devtype': 'cdrom', 'read-only': 'yes'}, persistent=True) + options={'devtype': 'cdrom', 'read-only': 'yes'}, + persistent=True) self.loop.run_until_complete(vm.devices['block'].attach(dev)) libvirt_xml = vm.create_config_file() self.assertXMLEqual(lxml.etree.XML(libvirt_xml), @@ -1585,7 +1586,8 @@ def test_600_libvirt_xml_hvm_cdrom_dom0_kernel_boot(self): self.app.vmm.offline_mode = False dev = qubes.devices.DeviceAssignment( dom0, 'sda', - {'devtype': 'cdrom', 'read-only': 'yes'}, persistent=True) + options={'devtype': 'cdrom', 'read-only': 'yes'}, + persistent=True) self.loop.run_until_complete(vm.devices['block'].attach(dev)) libvirt_xml = vm.create_config_file() self.assertXMLEqual(lxml.etree.XML(libvirt_xml), diff --git a/qubes/tools/__init__.py b/qubes/tools/__init__.py index 0dc2c2c2b..9a28c8810 100644 --- a/qubes/tools/__init__.py +++ b/qubes/tools/__init__.py @@ -74,6 +74,7 @@ class SinglePropertyAction(argparse.Action): '''Action for argument parser that stores a property.''' # pylint: disable=redefined-builtin,too-few-public-methods + # pylint: disable=too-many-positional-arguments def __init__(self, option_strings, dest, diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index b3be66e92..269648904 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -278,7 +278,7 @@ def load_extras(self): device_assignment = qubes.devices.DeviceAssignment( self.app.domains[node.get('backend-domain')], node.get('id'), - options, + options=options, persistent=True ) self.devices[devclass].load_persistent(device_assignment) diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 5ad40c9ae..aab916917 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -1490,8 +1490,9 @@ async def unpause(self): return self - async def run_service(self, service, source=None, user=None, stubdom=False, - filter_esc=False, autostart=False, gui=False, **kwargs): + async def run_service(self, service, source=None, user=None, *, + stubdom=False, + filter_esc=False, autostart=False, gui=False, **kwargs): """Run service on this VM :param str service: service name