Skip to content

Commit

Permalink
pylint: deal with too-many-positional-arguments
Browse files Browse the repository at this point in the history
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 caf0dae)
Adjust for old devices API in release4.2 branch.
  • Loading branch information
marmarek committed Dec 8, 2024
1 parent 0811926 commit fd445f5
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
2 changes: 1 addition & 1 deletion qubes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions qubes/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class BackupHeader:
int_options = ['version']

def __init__(self,
*,
version=None,
encrypted=None,
compressed=None,
Expand Down
2 changes: 1 addition & 1 deletion qubes/dochelpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
2 changes: 1 addition & 1 deletion qubes/storage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions qubes/storage/zfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions qubes/tests/api_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
6 changes: 4 additions & 2 deletions qubes/tests/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions qubes/tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion qubes/vm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd445f5

Please sign in to comment.