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.
  • Loading branch information
marmarek committed Sep 26, 2024
1 parent c30178a commit caf0dae
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 15 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
4 changes: 2 additions & 2 deletions qubes/api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ async def vm_device_unassign(self, endpoint):
self.fire_event_for_permission(device=dev, devclass=devclass)

assignment = qubes.device_protocol.DeviceAssignment(
dev.backend_domain, dev.ident, devclass)
dev.backend_domain, dev.ident, devclass=devclass)
await self.dest.devices[devclass].unassign(assignment)
self.app.save()

Expand Down Expand Up @@ -1390,7 +1390,7 @@ async def vm_device_detach(self, endpoint):
self.fire_event_for_permission(device=dev, devclass=devclass)

assignment = qubes.device_protocol.DeviceAssignment(
dev.backend_domain, dev.ident, devclass)
dev.backend_domain, dev.ident, devclass=devclass)
await self.dest.devices[devclass].detach(assignment)

# Assign/Unassign action can modify only a persistent state of running VM.
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
5 changes: 4 additions & 1 deletion qubes/device_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
The same in `qubes-core-admin` and `qubes-core-admin-client`,
should be moved to one place.
"""


import string
import sys
from enum import Enum
Expand Down Expand Up @@ -433,6 +435,7 @@ def __init__(
self,
backend_domain: QubesVM,
ident: str,
*,
devclass: Optional[str] = None,
vendor: Optional[str] = None,
product: Optional[str] = None,
Expand Down Expand Up @@ -790,7 +793,7 @@ class DeviceAssignment(Device):
and required to start domain.
"""

def __init__(self, backend_domain, ident, options=None,
def __init__(self, backend_domain, ident, *, options=None,
frontend_domain=None, devclass=None,
required=False, attach_automatically=False):
super().__init__(backend_domain, ident, devclass)
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
6 changes: 3 additions & 3 deletions qubes/tests/api_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ def test_471_vm_device_list_assigned_options(self):
def device_list_single_attached_testclass(self, vm, event, **kwargs):
if vm is not self.vm:
return
dev = qubes.device_protocol.DeviceInfo(self.vm, '1234', 'testclass')
dev = qubes.device_protocol.DeviceInfo(self.vm, '1234', devclass='testclass')
yield (dev, {'attach_opt': 'value'})

def test_472_vm_device_list_attached(self):
Expand Down Expand Up @@ -1823,9 +1823,9 @@ def test_473_vm_device_list_assigned_specific(self):
def device_list_multiple_attached_testclass(self, vm, event, **kwargs):
if vm is not self.vm:
return
dev = qubes.device_protocol.DeviceInfo(self.vm, '1234', 'testclass')
dev = qubes.device_protocol.DeviceInfo(self.vm, '1234', devclass='testclass')
yield (dev, {'attach_opt': 'value'})
dev = qubes.device_protocol.DeviceInfo(self.vm, '4321', 'testclass')
dev = qubes.device_protocol.DeviceInfo(self.vm, '4321', devclass='testclass')
yield (dev, {'attach_opt': 'value'})

def test_474_vm_device_list_attached_specific(self):
Expand Down
2 changes: 1 addition & 1 deletion qubes/tests/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __init__(self, app, name, *args, **kwargs):
super(TestVM, self).__init__(*args, **kwargs)
self.app = app
self.name = name
self.device = TestDevice(self, 'testdev', 'testclass')
self.device = TestDevice(self, 'testdev', devclass='testclass')
self.events_enabled = True
self.devices = {
'testclass': qubes.devices.DeviceCollection(self, 'testclass')
Expand Down
4 changes: 2 additions & 2 deletions qubes/tests/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ def test_600_libvirt_xml_hvm_cdrom_boot(self):
self.app.vmm.offline_mode = False
dev = qubes.device_protocol.DeviceAssignment(
dom0, 'sda',
{'devtype': 'cdrom', 'read-only': 'yes'},
options={'devtype': 'cdrom', 'read-only': 'yes'},
attach_automatically=True, required=True)
self.loop.run_until_complete(vm.devices['block'].assign(dev))
libvirt_xml = vm.create_config_file()
Expand Down Expand Up @@ -1587,7 +1587,7 @@ def test_600_libvirt_xml_hvm_cdrom_dom0_kernel_boot(self):
self.app.vmm.offline_mode = False
dev = qubes.device_protocol.DeviceAssignment(
dom0, 'sda',
{'devtype': 'cdrom', 'read-only': 'yes'},
options={'devtype': 'cdrom', 'read-only': 'yes'},
attach_automatically=True, required=True)
self.loop.run_until_complete(vm.devices['block'].assign(dev))
libvirt_xml = vm.create_config_file()
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 @@ -287,7 +287,7 @@ def load_extras(self):
device_assignment = qubes.device_protocol.DeviceAssignment(
self.app.domains[node.get('backend-domain')],
node.get('id'),
options,
options=options,
attach_automatically=True,
# backward compatibility: persistent~>required=True
required=qubes.property.bool(
Expand Down
5 changes: 3 additions & 2 deletions qubes/vm/qubesvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,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 caf0dae

Please sign in to comment.