diff --git a/qubes/app.py b/qubes/app.py
index 00c7c126..2709ccc1 100644
--- a/qubes/app.py
+++ b/qubes/app.py
@@ -480,7 +480,7 @@ class VMCollection(object):
# if not self[netvm_qid].is_netvm():
# return set([])
- while len(new_vms) > 0:
+ while new_vms:
cur_vm = new_vms.pop()
for vm in cur_vm.connected_vms:
if vm in dependent_vms:
diff --git a/qubes/devices.py b/qubes/devices.py
index e51af94a..4fc24ebd 100644
--- a/qubes/devices.py
+++ b/qubes/devices.py
@@ -216,8 +216,7 @@ class DeviceCollection(object):
if dev:
assert len(dev) == 1
return dev[0]
- else:
- return UnknownDevice(self._vm, ident)
+ return UnknownDevice(self._vm, ident)
class DeviceManager(dict):
diff --git a/qubes/firewall.py b/qubes/firewall.py
index 6861bcb3..804f7d58 100644
--- a/qubes/firewall.py
+++ b/qubes/firewall.py
@@ -406,8 +406,7 @@ class Firewall(object):
def _translate_action(key):
if xml_root.get(key, policy_v1) == 'allow':
return Action.accept
- else:
- return Action.drop
+ return Action.drop
self.rules.append(Rule(None,
action=_translate_action('dns'),
diff --git a/qubes/rngdoc.py b/qubes/rngdoc.py
index 205b7ea3..5730f8b3 100755
--- a/qubes/rngdoc.py
+++ b/qubes/rngdoc.py
@@ -55,8 +55,7 @@ class Element(object):
if wrap:
return ''.join(self.schema.wrapper.fill(p) + '\n\n'
for p in textwrap.dedent(xml.text.strip('\n')).split('\n\n'))
- else:
- return ' '.join(xml.text.strip().split())
+ return ' '.join(xml.text.strip().split())
def get_data_type(self, xml=None):
@@ -93,7 +92,7 @@ class Element(object):
for xml in self.xml.xpath('''./rng:attribute |
./rng:optional/rng:attribute |
./rng:choice/rng:attribute''', namespaces=self.nsmap):
- required = xml.getparent() == self.xml and 'yes' or 'no'
+ required = 'yes' if xml.getparent() == self.xml else 'no'
yield (xml, required)
@@ -212,6 +211,6 @@ Quick example, worth thousands lines of specification:
if __name__ == '__main__':
- main(*sys.argv[1:])
+ main(*sys.argv[1:]) # pylint: disable=no-value-for-parameter
# vim: ts=4 sw=4 et
diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py
index 1f8aa44a..fa8bc80d 100644
--- a/qubes/storage/__init__.py
+++ b/qubes/storage/__init__.py
@@ -446,8 +446,7 @@ class Storage(object):
"You need to pass a Volume or pool name as str"
if isinstance(volume, Volume):
return self.pools[volume.name]
- else:
- return self.vm.app.pools[volume]
+ return self.vm.app.pools[volume]
def commit(self):
''' Makes changes to an 'origin' volume persistent '''
@@ -476,8 +475,7 @@ class Storage(object):
"You need to pass a Volume or pool name as str"
if isinstance(volume, Volume):
return self.pools[volume.name].export(volume)
- else:
- return self.pools[volume].export(self.vm.volumes[volume])
+ return self.pools[volume].export(self.vm.volumes[volume])
class Pool(object):
diff --git a/qubes/storage/file.py b/qubes/storage/file.py
index 1f939b0f..1a07224c 100644
--- a/qubes/storage/file.py
+++ b/qubes/storage/file.py
@@ -378,10 +378,9 @@ class FileVolume(qubes.storage.Volume):
if not os.path.exists(old_revision):
return {}
- else:
- seconds = os.path.getctime(old_revision)
- iso_date = qubes.storage.isodate(seconds).split('.', 1)[0]
- return {iso_date: old_revision}
+ seconds = os.path.getctime(old_revision)
+ iso_date = qubes.storage.isodate(seconds).split('.', 1)[0]
+ return {iso_date: old_revision}
@property
def usage(self):
diff --git a/qubes/storage/lvm.py b/qubes/storage/lvm.py
index 58137148..051d75dc 100644
--- a/qubes/storage/lvm.py
+++ b/qubes/storage/lvm.py
@@ -401,8 +401,7 @@ class ThinVolume(qubes.storage.Volume):
return qubes.devices.BlockDevice(
'/dev/' + self._vid_snap, self.name, self.script,
self.rw, self.domain, self.devtype)
- else:
- return super(ThinVolume, self).block_device()
+ return super(ThinVolume, self).block_device()
@property
def usage(self): # lvm thin usage always returns at least the same usage as
diff --git a/qubes/tarwriter.py b/qubes/tarwriter.py
index 35bef30d..bc9e90dd 100644
--- a/qubes/tarwriter.py
+++ b/qubes/tarwriter.py
@@ -38,10 +38,9 @@ class TarSparseInfo(tarfile.TarInfo):
@property
def realsize(self):
- if len(self.sparsemap):
+ if self.sparsemap:
return self.sparsemap[-1][0] + self.sparsemap[-1][1]
- else:
- return self.size
+ return self.size
def sparse_header_chunk(self, index):
if index < len(self.sparsemap):
@@ -49,8 +48,7 @@ class TarSparseInfo(tarfile.TarInfo):
tarfile.itn(self.sparsemap[index][0], 12, tarfile.GNU_FORMAT),
tarfile.itn(self.sparsemap[index][1], 12, tarfile.GNU_FORMAT),
])
- else:
- return b'\0' * 12 * 2
+ return b'\0' * 12 * 2
def get_gnu_header(self):
'''Part placed in 'prefix' field of posix header'''
@@ -81,8 +79,7 @@ class TarSparseInfo(tarfile.TarInfo):
header_buf = super(TarSparseInfo, self).tobuf(format, encoding, errors)
if len(self.sparsemap) > 4:
return header_buf + b''.join(self.create_ext_sparse_headers())
- else:
- return header_buf
+ return header_buf
def create_ext_sparse_headers(self):
for ext_hdr in range(4, len(self.sparsemap), 21):
diff --git a/qubes/tools/__init__.py b/qubes/tools/__init__.py
index f17abde3..3fc5e794 100644
--- a/qubes/tools/__init__.py
+++ b/qubes/tools/__init__.py
@@ -258,7 +258,7 @@ class VolumeAction(QubesAction):
pool = app.pools[pool_name]
volume = [v for v in pool.volumes if v.vid == vid]
assert volume > 1, 'Duplicate vids in pool %s' % pool_name
- if len(volume) == 0:
+ if not volume:
parser.error_runtime(
'no volume with id {!r} pool: {!r}'.format(vid,
pool_name))
@@ -353,6 +353,7 @@ class QubesArgumentParser(argparse.ArgumentParser):
self.set_defaults(verbose=1, quiet=0)
def parse_args(self, *args, **kwargs):
+ # pylint: disable=arguments-differ
namespace = super(QubesArgumentParser, self).parse_args(*args, **kwargs)
if self._want_app and not self._want_app_no_instance:
@@ -433,7 +434,7 @@ class AliasedSubParsersAction(argparse._SubParsersAction):
# source https://gist.github.com/sampsyo/471779
# pylint: disable=protected-access,too-few-public-methods
class _AliasedPseudoAction(argparse.Action):
- # pylint: disable=redefined-builtin
+ # pylint: disable=redefined-builtin,arguments-differ
def __init__(self, name, aliases, help):
dest = name
if aliases:
@@ -442,8 +443,7 @@ class AliasedSubParsersAction(argparse._SubParsersAction):
sup.__init__(option_strings=[], dest=dest, help=help)
def __call__(self, **kwargs):
- super(AliasedSubParsersAction._AliasedPseudoAction, self).__call__(
- **kwargs)
+ pass
def add_parser(self, name, **kwargs):
if 'aliases' in kwargs:
diff --git a/qubes/tools/qubesd.py b/qubes/tools/qubesd.py
index e72a7dd7..65e5138b 100644
--- a/qubes/tools/qubesd.py
+++ b/qubes/tools/qubesd.py
@@ -42,6 +42,7 @@ class QubesDaemonProtocol(asyncio.Protocol):
self.untrusted_buffer.close()
def data_received(self, untrusted_data):
+ # pylint: disable=arguments-differ
print('data_received(untrusted_data={!r})'.format(untrusted_data))
if self.len_untrusted_buffer + len(untrusted_data) > self.buffer_size:
self.app.log.warning('request too long')
diff --git a/qubes/tools/qvm_backup_restore.py b/qubes/tools/qvm_backup_restore.py
index 88dbf1f4..d8cc87f0 100644
--- a/qubes/tools/qvm_backup_restore.py
+++ b/qubes/tools/qvm_backup_restore.py
@@ -204,7 +204,6 @@ def main(args=None):
"and (if encrypted) decrypt the backup: ")
encoding = sys.stdin.encoding or locale.getpreferredencoding()
- # pylint: disable=redefined-variable-type
passphrase = passphrase.decode(encoding)
args.app.log.info("Checking backup content...")
diff --git a/qubes/tools/qvm_check.py b/qubes/tools/qvm_check.py
index 0a911528..756e4695 100644
--- a/qubes/tools/qvm_check.py
+++ b/qubes/tools/qvm_check.py
@@ -38,6 +38,7 @@ parser.add_argument("--template", action="store_true", dest="template",
def print_msg(domains, what_single, what_plural):
+ # pylint: disable=len-as-condition
if len(domains) == 0:
print("None of given VM {!s}".format(what_single))
elif len(domains) == 1:
diff --git a/qubes/tools/qvm_ls.py b/qubes/tools/qvm_ls.py
index 4748b3f0..c477346f 100644
--- a/qubes/tools/qvm_ls.py
+++ b/qubes/tools/qvm_ls.py
@@ -309,8 +309,7 @@ class StatusColumn(Column):
if ret is not None:
if getattr(vm, 'hvm', False):
return ret.upper()
- else:
- return ret
+ return ret
@flag(2)
@@ -478,8 +477,7 @@ class Table(object):
'''Format single table row (all columns for one domain).'''
if self.raw_data:
return '|'.join(col.format(vm) for col in self.columns)
- else:
- return ''.join(col.cell(vm) for col in self.columns)
+ return ''.join(col.cell(vm) for col in self.columns)
def write_table(self, stream=sys.stdout):
diff --git a/qubes/tools/qvm_pool.py b/qubes/tools/qvm_pool.py
index 2c141988..4c028b8a 100644
--- a/qubes/tools/qvm_pool.py
+++ b/qubes/tools/qvm_pool.py
@@ -84,7 +84,7 @@ def list_pools(app):
''' Prints out all known pools and their drivers '''
result = [('NAME', 'DRIVER')]
for pool in app.pools.values():
- if len(pool.volumes) == 0 and issubclass(
+ if not pool.volumes and issubclass(
pool.__class__, qubes.storage.domain.DomainPool):
# skip empty DomainPools
continue
diff --git a/qubes/utils.py b/qubes/utils.py
index 39a78943..d15300dc 100644
--- a/qubes/utils.py
+++ b/qubes/utils.py
@@ -111,22 +111,19 @@ def parse_size(size):
def mbytes_to_kmg(size):
if size > 1024:
return "%d GiB" % (size / 1024)
- else:
- return "%d MiB" % size
+ return "%d MiB" % size
def kbytes_to_kmg(size):
if size > 1024:
return mbytes_to_kmg(size / 1024)
- else:
- return "%d KiB" % size
+ return "%d KiB" % size
def bytes_to_kmg(size):
if size > 1024:
return kbytes_to_kmg(size / 1024)
- else:
- return "%d B" % size
+ return "%d B" % size
def size_to_human(size):
@@ -137,8 +134,7 @@ def size_to_human(size):
return str(round(size / 1024.0, 1)) + ' KiB'
elif size < 1024 * 1024 * 1024:
return str(round(size / (1024.0 * 1024), 1)) + ' MiB'
- else:
- return str(round(size / (1024.0 * 1024 * 1024), 1)) + ' GiB'
+ return str(round(size / (1024.0 * 1024 * 1024), 1)) + ' GiB'
def urandom(size):
diff --git a/qubes/vm/adminvm.py b/qubes/vm/adminvm.py
index a571a3de..cd852ceb 100644
--- a/qubes/vm/adminvm.py
+++ b/qubes/vm/adminvm.py
@@ -132,7 +132,7 @@ class AdminVM(qubes.vm.qubesvm.QubesVM):
.. seealso:
:py:meth:`qubes.vm.qubesvm.QubesVM.start`
- ''' # pylint: disable=unused-argument
+ ''' # pylint: disable=unused-argument,arguments-differ
raise qubes.exc.QubesVMError(self, 'Cannot start Dom0 fake domain!')
def suspend(self):
diff --git a/qubes/vm/mix/net.py b/qubes/vm/mix/net.py
index 8597e30f..d2f82370 100644
--- a/qubes/vm/mix/net.py
+++ b/qubes/vm/mix/net.py
@@ -49,8 +49,7 @@ def _default_ip(self):
return None
if self.netvm is not None:
return self.netvm.get_ip_for_vm(self) # pylint: disable=no-member
- else:
- return self.get_ip_for_vm(self)
+ return self.get_ip_for_vm(self)
def _setter_ip(self, prop, value):
@@ -173,8 +172,7 @@ class NetVMMixin(qubes.events.Emitter):
'10.139.1.1',
'10.139.1.2',
)
- else:
- return None
+ return None
def __init__(self, *args, **kwargs):
self._firewall = None
diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py
index 8365cd6b..cc63a41c 100644
--- a/qubes/vm/qubesvm.py
+++ b/qubes/vm/qubesvm.py
@@ -427,6 +427,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
doc='Kernel used by this domain.')
# CORE2: swallowed uses_default_kernelopts
+ # pylint: disable=no-member
kernelopts = qubes.property('kernelopts', type=str, load_stage=4,
default=(lambda self: qubes.config.defaults['kernelopts_pcidevs']
if list(self.devices['pci'].attached(persistent=True))
@@ -449,6 +450,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
ls_width=12,
doc='FIXME')
+ # pylint: enable=no-member
+
# @property
# def default_user(self):
# if self.template is not None:
@@ -1430,15 +1433,12 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
else:
if not self.is_fully_usable():
return "Transient"
- else:
- return "Running"
- else:
- return 'Halted'
+ return "Running"
+ return 'Halted'
except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_NO_DOMAIN:
return 'Halted'
- else:
- raise
+ raise
assert False
@@ -1612,8 +1612,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
'/vm/{}/start_time'.format(self.uuid))
if start_time != '':
return datetime.datetime.fromtimestamp(float(start_time))
- else:
- return None
+ return None
def is_outdated(self):
'''Check whether domain needs restart to update root image from \
diff --git a/qubespolicy/__init__.py b/qubespolicy/__init__.py
index 6f3e879f..e092f711 100755
--- a/qubespolicy/__init__.py
+++ b/qubespolicy/__init__.py
@@ -364,7 +364,7 @@ class PolicyAction(object):
self.target = target
self.action = Action.allow
else:
- self.action = Action.deny # pylint: disable=redefined-variable-type
+ self.action = Action.deny
raise AccessDenied(
'denied by the user {}:{}'.format(self.rule.filename,
self.rule.lineno))
@@ -569,7 +569,7 @@ class Policy(object):
else:
targets = list(
self.collect_targets_for_ask(system_info, source))
- if len(targets) == 0:
+ if not targets:
raise AccessDenied(
'policy define \'ask\' action at {}:{} but no target is '
'available to choose from'.format(
diff --git a/qubespolicy/rpcconfirmation.py b/qubespolicy/rpcconfirmation.py
index 50189276..ee14204c 100644
--- a/qubespolicy/rpcconfirmation.py
+++ b/qubespolicy/rpcconfirmation.py
@@ -119,7 +119,7 @@ class RPCConfirmationWindow:
partitioned = escaped.partition('.')
formatted = partitioned[0] + partitioned[1]
- if len(partitioned[2]) > 0:
+ if partitioned[2]:
formatted += "" + partitioned[2] + ""
else:
formatted = "" + formatted + ""
@@ -203,8 +203,7 @@ class RPCConfirmationWindow:
if self._confirmed:
return self._target_name
- else:
- return False
+ return False
def confirm_rpc(entries_info, source, rpc_operation, targets_list, target=None):