diff --git a/qubes/__init__.py b/qubes/__init__.py index fae5bbb3..4bc8e41f 100644 --- a/qubes/__init__.py +++ b/qubes/__init__.py @@ -233,10 +233,9 @@ class property: # pylint: disable=redefined-builtin,invalid-name if self._default is self._NO_DEFAULT: raise AttributeError( 'property {!r} have no default'.format(self.__name__)) - elif self._default_function: + if self._default_function: return self._default_function(instance) - else: - return self._default + return self._default def __set__(self, instance, value): self._enforce_write_once(instance) @@ -734,9 +733,8 @@ class PropertyHolder(qubes.events.Emitter): msg = 'Required property {!r} not set on {!r}'.format(prop, self) if hard: raise ValueError(msg) - else: - # pylint: disable=no-member - self.log.fatal(msg) + # pylint: disable=no-member + self.log.fatal(msg) def close(self): diff --git a/qubes/firewall.py b/qubes/firewall.py index 0ca8f25c..efcf407e 100644 --- a/qubes/firewall.py +++ b/qubes/firewall.py @@ -96,7 +96,7 @@ class DstHost(RuleOption): def __init__(self, untrusted_value, prefixlen=None): if untrusted_value.count('/') > 1: raise ValueError('Too many /: ' + untrusted_value) - elif not untrusted_value.count('/'): + if not untrusted_value.count('/'): # add prefix length to bare IP addresses try: socket.inet_pton(socket.AF_INET6, untrusted_value) diff --git a/qubes/storage/__init__.py b/qubes/storage/__init__.py index 9079a830..cab68eb1 100644 --- a/qubes/storage/__init__.py +++ b/qubes/storage/__init__.py @@ -110,7 +110,7 @@ class Volume: msg = "snap_on_start specified on {!r} but no volume source set" msg = msg.format(name) raise StoragePoolException(msg) - elif not snap_on_start and source is not None: + if not snap_on_start and source is not None: msg = "source specified on {!r} but no snap_on_start set" msg = msg.format(name) raise StoragePoolException(msg) diff --git a/qubes/utils.py b/qubes/utils.py index ccf96b08..23dddd99 100644 --- a/qubes/utils.py +++ b/qubes/utils.py @@ -150,7 +150,7 @@ def get_entry_point_one(group, name): epoints = tuple(pkg_resources.iter_entry_points(group, name)) if not epoints: raise KeyError(name) - elif len(epoints) > 1: + if len(epoints) > 1: raise TypeError( 'more than 1 implementation of {!r} found: {}'.format(name, ', '.join('{}.{}'.format(ep.module_name, '.'.join(ep.attrs)) diff --git a/qubes/vm/__init__.py b/qubes/vm/__init__.py index 2f8d6281..0b4ac6f8 100644 --- a/qubes/vm/__init__.py +++ b/qubes/vm/__init__.py @@ -48,9 +48,8 @@ def validate_name(holder, prop, value): raise qubes.exc.QubesPropertyValueError(holder, prop, value, '{} value must be shorter than 32 characters'.format( prop.__name__)) - else: - raise qubes.exc.QubesValueError( - 'VM name must be shorter than 32 characters') + raise qubes.exc.QubesValueError( + 'VM name must be shorter than 32 characters') # this regexp does not contain '+'; if it had it, we should specifically # disallow 'lost+found' #1440 @@ -58,9 +57,8 @@ def validate_name(holder, prop, value): if holder is not None and prop is not None: raise qubes.exc.QubesPropertyValueError(holder, prop, value, '{} value contains illegal characters'.format(prop.__name__)) - else: - raise qubes.exc.QubesValueError( - 'VM name contains illegal characters') + raise qubes.exc.QubesValueError( + 'VM name contains illegal characters') if value in ('none', 'default'): raise qubes.exc.QubesValueError( 'VM name cannot be \'none\' nor \'default\'') diff --git a/qubes/vm/qubesvm.py b/qubes/vm/qubesvm.py index 5dbb2596..2c8d7a4c 100644 --- a/qubes/vm/qubesvm.py +++ b/qubes/vm/qubesvm.py @@ -822,7 +822,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): return self.name < other.name def __xml__(self): + # pylint: disable=no-member element = super(QubesVM, self).__xml__() + # pylint: enable=no-member if hasattr(self, 'volumes'): volume_config_node = lxml.etree.Element('volume-config') @@ -840,6 +842,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): def on_domain_init_loaded(self, event): # pylint: disable=unused-argument if not hasattr(self, 'uuid'): + # pylint: disable=attribute-defined-outside-init self.uuid = uuid.uuid4() # Initialize VM image storage class; @@ -1192,8 +1195,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): except libvirt.libvirtError as e: if e.get_error_code() == libvirt.VIR_ERR_OPERATION_INVALID: raise qubes.exc.QubesVMNotStartedError(self) - else: - raise + raise # make sure all shutdown tasks are completed yield from self._ensure_shutdown_handled() @@ -1305,7 +1307,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): # XXX what about autostart? raise qubes.exc.QubesVMNotRunningError( self, 'Domain {!r} is paused'.format(self.name)) - elif not self.is_running(): + if not self.is_running(): if not autostart: raise qubes.exc.QubesVMNotRunningError(self) yield from self.start(start_guid=gui) @@ -1518,9 +1520,8 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): 'see /var/log/xen/console/guest-{}.log for details'.format( self.qrexec_timeout, self.name )) - else: - raise qubes.exc.QubesVMError(self, - 'qrexec-daemon startup failed: ' + err.stderr.decode()) + raise qubes.exc.QubesVMError(self, + 'qrexec-daemon startup failed: ' + err.stderr.decode()) @asyncio.coroutine def start_qubesdb(self): @@ -2094,8 +2095,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM): raise qubes.exc.QubesVMError(self, 'HVM qubes are not supported on this machine. ' 'Check BIOS settings for VT-x/AMD-V extensions.') - else: - raise + raise # # workshop -- those are to be reworked later diff --git a/qubespolicy/__init__.py b/qubespolicy/__init__.py index 927932c8..20544ed3 100755 --- a/qubespolicy/__init__.py +++ b/qubespolicy/__init__.py @@ -416,7 +416,7 @@ class PolicyAction(object): # this should be really rejected by Policy.eval() raise AccessDenied( 'denied by policy {}:{}'.format(rule.filename, rule.lineno)) - elif rule.action == Action.ask: + if rule.action == Action.ask: if targets_for_ask is None: raise AccessDenied( 'invalid policy {}:{}'.format(rule.filename, rule.lineno))