Make pylint happy

Fix multiple instances of 'no-else-raise' warning.
This commit is contained in:
Marek Marczykowski-Górecki 2019-02-27 16:19:29 +01:00
parent 933882ee9b
commit 092fb9659d
No known key found for this signature in database
GPG Key ID: 063938BA42CFA724
7 changed files with 20 additions and 24 deletions

View File

@ -233,9 +233,8 @@ 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
def __set__(self, instance, value):
@ -734,7 +733,6 @@ 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)

View File

@ -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)

View File

@ -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)

View File

@ -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))

View File

@ -48,7 +48,6 @@ 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')
@ -58,7 +57,6 @@ 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')
if value in ('none', 'default'):

View File

@ -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,7 +1195,6 @@ 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
# make sure all shutdown tasks are completed
@ -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,7 +1520,6 @@ 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())
@ -2094,7 +2095,6 @@ 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
#

View File

@ -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))