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,10 +233,9 @@ class property: # pylint: disable=redefined-builtin,invalid-name
if self._default is self._NO_DEFAULT: if self._default is self._NO_DEFAULT:
raise AttributeError( raise AttributeError(
'property {!r} have no default'.format(self.__name__)) 'property {!r} have no default'.format(self.__name__))
elif self._default_function: if self._default_function:
return self._default_function(instance) return self._default_function(instance)
else: return self._default
return self._default
def __set__(self, instance, value): def __set__(self, instance, value):
self._enforce_write_once(instance) 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) msg = 'Required property {!r} not set on {!r}'.format(prop, self)
if hard: if hard:
raise ValueError(msg) raise ValueError(msg)
else: # pylint: disable=no-member
# pylint: disable=no-member self.log.fatal(msg)
self.log.fatal(msg)
def close(self): def close(self):

View File

@ -96,7 +96,7 @@ class DstHost(RuleOption):
def __init__(self, untrusted_value, prefixlen=None): def __init__(self, untrusted_value, prefixlen=None):
if untrusted_value.count('/') > 1: if untrusted_value.count('/') > 1:
raise ValueError('Too many /: ' + untrusted_value) raise ValueError('Too many /: ' + untrusted_value)
elif not untrusted_value.count('/'): if not untrusted_value.count('/'):
# add prefix length to bare IP addresses # add prefix length to bare IP addresses
try: try:
socket.inet_pton(socket.AF_INET6, untrusted_value) 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 = "snap_on_start specified on {!r} but no volume source set"
msg = msg.format(name) msg = msg.format(name)
raise StoragePoolException(msg) 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 = "source specified on {!r} but no snap_on_start set"
msg = msg.format(name) msg = msg.format(name)
raise StoragePoolException(msg) 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)) epoints = tuple(pkg_resources.iter_entry_points(group, name))
if not epoints: if not epoints:
raise KeyError(name) raise KeyError(name)
elif len(epoints) > 1: if len(epoints) > 1:
raise TypeError( raise TypeError(
'more than 1 implementation of {!r} found: {}'.format(name, 'more than 1 implementation of {!r} found: {}'.format(name,
', '.join('{}.{}'.format(ep.module_name, '.'.join(ep.attrs)) ', '.join('{}.{}'.format(ep.module_name, '.'.join(ep.attrs))

View File

@ -48,9 +48,8 @@ def validate_name(holder, prop, value):
raise qubes.exc.QubesPropertyValueError(holder, prop, value, raise qubes.exc.QubesPropertyValueError(holder, prop, value,
'{} value must be shorter than 32 characters'.format( '{} value must be shorter than 32 characters'.format(
prop.__name__)) prop.__name__))
else: raise qubes.exc.QubesValueError(
raise qubes.exc.QubesValueError( 'VM name must be shorter than 32 characters')
'VM name must be shorter than 32 characters')
# this regexp does not contain '+'; if it had it, we should specifically # this regexp does not contain '+'; if it had it, we should specifically
# disallow 'lost+found' #1440 # disallow 'lost+found' #1440
@ -58,9 +57,8 @@ def validate_name(holder, prop, value):
if holder is not None and prop is not None: if holder is not None and prop is not None:
raise qubes.exc.QubesPropertyValueError(holder, prop, value, raise qubes.exc.QubesPropertyValueError(holder, prop, value,
'{} value contains illegal characters'.format(prop.__name__)) '{} value contains illegal characters'.format(prop.__name__))
else: raise qubes.exc.QubesValueError(
raise qubes.exc.QubesValueError( 'VM name contains illegal characters')
'VM name contains illegal characters')
if value in ('none', 'default'): if value in ('none', 'default'):
raise qubes.exc.QubesValueError( raise qubes.exc.QubesValueError(
'VM name cannot be \'none\' nor \'default\'') 'VM name cannot be \'none\' nor \'default\'')

View File

@ -822,7 +822,9 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
return self.name < other.name return self.name < other.name
def __xml__(self): def __xml__(self):
# pylint: disable=no-member
element = super(QubesVM, self).__xml__() element = super(QubesVM, self).__xml__()
# pylint: enable=no-member
if hasattr(self, 'volumes'): if hasattr(self, 'volumes'):
volume_config_node = lxml.etree.Element('volume-config') 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): def on_domain_init_loaded(self, event):
# pylint: disable=unused-argument # pylint: disable=unused-argument
if not hasattr(self, 'uuid'): if not hasattr(self, 'uuid'):
# pylint: disable=attribute-defined-outside-init
self.uuid = uuid.uuid4() self.uuid = uuid.uuid4()
# Initialize VM image storage class; # Initialize VM image storage class;
@ -1192,8 +1195,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
except libvirt.libvirtError as e: except libvirt.libvirtError as e:
if e.get_error_code() == libvirt.VIR_ERR_OPERATION_INVALID: if e.get_error_code() == libvirt.VIR_ERR_OPERATION_INVALID:
raise qubes.exc.QubesVMNotStartedError(self) raise qubes.exc.QubesVMNotStartedError(self)
else: raise
raise
# make sure all shutdown tasks are completed # make sure all shutdown tasks are completed
yield from self._ensure_shutdown_handled() yield from self._ensure_shutdown_handled()
@ -1305,7 +1307,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
# XXX what about autostart? # XXX what about autostart?
raise qubes.exc.QubesVMNotRunningError( raise qubes.exc.QubesVMNotRunningError(
self, 'Domain {!r} is paused'.format(self.name)) self, 'Domain {!r} is paused'.format(self.name))
elif not self.is_running(): if not self.is_running():
if not autostart: if not autostart:
raise qubes.exc.QubesVMNotRunningError(self) raise qubes.exc.QubesVMNotRunningError(self)
yield from self.start(start_guid=gui) 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( 'see /var/log/xen/console/guest-{}.log for details'.format(
self.qrexec_timeout, self.name self.qrexec_timeout, self.name
)) ))
else: raise qubes.exc.QubesVMError(self,
raise qubes.exc.QubesVMError(self, 'qrexec-daemon startup failed: ' + err.stderr.decode())
'qrexec-daemon startup failed: ' + err.stderr.decode())
@asyncio.coroutine @asyncio.coroutine
def start_qubesdb(self): def start_qubesdb(self):
@ -2094,8 +2095,7 @@ class QubesVM(qubes.vm.mix.net.NetVMMixin, qubes.vm.BaseVM):
raise qubes.exc.QubesVMError(self, raise qubes.exc.QubesVMError(self,
'HVM qubes are not supported on this machine. ' 'HVM qubes are not supported on this machine. '
'Check BIOS settings for VT-x/AMD-V extensions.') 'Check BIOS settings for VT-x/AMD-V extensions.')
else: raise
raise
# #
# workshop -- those are to be reworked later # workshop -- those are to be reworked later

View File

@ -416,7 +416,7 @@ class PolicyAction(object):
# this should be really rejected by Policy.eval() # this should be really rejected by Policy.eval()
raise AccessDenied( raise AccessDenied(
'denied by policy {}:{}'.format(rule.filename, rule.lineno)) 'denied by policy {}:{}'.format(rule.filename, rule.lineno))
elif rule.action == Action.ask: if rule.action == Action.ask:
if targets_for_ask is None: if targets_for_ask is None:
raise AccessDenied( raise AccessDenied(
'invalid policy {}:{}'.format(rule.filename, rule.lineno)) 'invalid policy {}:{}'.format(rule.filename, rule.lineno))