commit b67ad564c472fe95d3373e0ed6cc6b722bed0b64 Author: Akihiro Motoki Date: Tue Sep 15 08:33:08 2020 +0900 pylint: Address no-else-continue/no-else-raise warnings Change-Id: I1d44c1bf564cf02908113a42b98e06057e993ec7 diff --git a/.pylintrc b/.pylintrc index 071d52d..5d102a8 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,10 +55,6 @@ disable= duplicate-code, inconsistent-return-statements, # TODO interface-not-implemented, - # Better to be fixed but too many hits :( - no-else-continue, # TODO - # Better to be fixed but too many hits :( - no-else-raise, # TODO no-else-return, no-self-use, # python3 way: Let's do it once we have a consensus. diff --git a/horizon/base.py b/horizon/base.py index ca3a22c..690e3e4 100644 --- a/horizon/base.py +++ b/horizon/base.py @@ -187,7 +187,7 @@ class Registry(object): """ if not inspect.isclass(cls): raise ValueError('Only classes may be registered.') - elif not issubclass(cls, self._registerable_class): + if not issubclass(cls, self._registerable_class): raise ValueError('Only %s classes or subclasses may be registered.' % self._registerable_class.__name__) @@ -233,11 +233,10 @@ class Registry(object): "slug": cls, "parent": parent, "name": self.slug}) - else: - slug = getattr(cls, "slug", cls) - raise NotRegistered('%(type)s with slug "%(slug)s" is not ' - 'registered.' % {"type": class_name, - "slug": slug}) + slug = getattr(cls, "slug", cls) + raise NotRegistered('%(type)s with slug "%(slug)s" is not ' + 'registered.' % {"type": class_name, + "slug": slug}) class Panel(HorizonComponent): @@ -821,8 +820,7 @@ class Site(Registry, HorizonComponent): # If it's not callable and not a string, it's wrong. raise ValueError('The user_home setting must be either a string ' 'or a callable object (e.g. a function).') - else: - return self.get_absolute_url() + return self.get_absolute_url() def get_absolute_url(self): """Returns the default URL for Horizon's URLconf. diff --git a/horizon/tables/views.py b/horizon/tables/views.py index e106a04..3915bb5 100644 --- a/horizon/tables/views.py +++ b/horizon/tables/views.py @@ -76,8 +76,7 @@ class MultiTableMixin(object): cls_name = self.__class__.__name__ raise NotImplementedError("You must define a %s method " "in %s." % (func_name, cls_name)) - else: - return func + return func def assign_type_string(self, data, type_name, data_type): for datum in data: diff --git a/horizon/workflows/base.py b/horizon/workflows/base.py index 3980e60..35f47f2 100644 --- a/horizon/workflows/base.py +++ b/horizon/workflows/base.py @@ -344,7 +344,7 @@ class Step(object): # If it's callable we know the function exists and is valid self._handlers[key].append(possible_handler) continue - elif not isinstance(possible_handler, str): + if not isinstance(possible_handler, str): raise TypeError("Connection handlers must be either " "callables or strings.") bits = possible_handler.split(".") @@ -789,7 +789,7 @@ class Workflow(html.HTMLElement, metaclass=WorkflowMetaclass): """Registers a :class:`~horizon.workflows.Step` with the workflow.""" if not inspect.isclass(step_class): raise ValueError('Only classes may be registered.') - elif not issubclass(step_class, cls._registerable_class): + if not issubclass(step_class, cls._registerable_class): raise ValueError('Only %s classes or subclasses may be registered.' % cls._registerable_class.__name__) if step_class in cls._cls_registry: @@ -852,7 +852,7 @@ class Workflow(html.HTMLElement, metaclass=WorkflowMetaclass): data = step.action.handle(self.request, self.context) if data is True or data is None: continue - elif data is False: + if data is False: partial = True else: self.context = step.contribute(data or {}, self.context) diff --git a/openstack_dashboard/dashboards/identity/domains/tables.py b/openstack_dashboard/dashboards/identity/domains/tables.py index 7fb879f..242481f 100644 --- a/openstack_dashboard/dashboards/identity/domains/tables.py +++ b/openstack_dashboard/dashboards/identity/domains/tables.py @@ -117,9 +117,9 @@ class DeleteDomainsAction(tables.DeleteAction): % domain.name messages.error(request, msg) raise keystoneclient_exceptions.ClientException(msg) - else: - LOG.info('Deleting domain "%s".', obj_id) - api.keystone.domain_delete(request, obj_id) + + LOG.info('Deleting domain "%s".', obj_id) + api.keystone.domain_delete(request, obj_id) class DisableDomainsAction(tables.BatchAction): diff --git a/openstack_dashboard/dashboards/project/images/images/forms.py b/openstack_dashboard/dashboards/project/images/images/forms.py index 94401ed..eeae6fc 100644 --- a/openstack_dashboard/dashboards/project/images/images/forms.py +++ b/openstack_dashboard/dashboards/project/images/images/forms.py @@ -246,11 +246,12 @@ class CreateImageForm(CreateParent): if not image_url and not image_file: msg = _("An image file or an external location must be specified.") if source_type == 'file': - raise ValidationError({'image_file': [msg, ]}) + error_msg = {'image_file': [msg, ]} else: - raise ValidationError({'image_url': [msg, ]}) - else: - return data + error_msg = {'image_url': [msg, ]} + raise ValidationError(error_msg) + + return data def handle(self, request, data): meta = api.glance.create_image_metadata(data) diff --git a/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py b/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py index 41ef8ac..bb6edb1 100644 --- a/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py +++ b/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py @@ -686,20 +686,20 @@ class CustomizeAction(workflows.Action): if upload_file._size > 16 * units.Ki: # 16kb msg = _('File exceeds maximum size (16kb)') raise forms.ValidationError(msg) - else: - script = upload_file.read() - if script != "": - try: - if not isinstance(script, str): - script = script.decode() - normalize_newlines(script) - except Exception as e: - msg = _('There was a problem parsing the' - ' %(prefix)s: %(error)s') - msg = msg % {'prefix': prefix, - 'error': e} - raise forms.ValidationError(msg) - return script + + script = upload_file.read() + if script != "": + try: + if not isinstance(script, str): + script = script.decode() + normalize_newlines(script) + except Exception as e: + msg = _('There was a problem parsing the' + ' %(prefix)s: %(error)s') + msg = msg % {'prefix': prefix, + 'error': e} + raise forms.ValidationError(msg) + return script else: return None diff --git a/openstack_dashboard/dashboards/project/vg_snapshots/views.py b/openstack_dashboard/dashboards/project/vg_snapshots/views.py index c827112..feb5050 100644 --- a/openstack_dashboard/dashboards/project/vg_snapshots/views.py +++ b/openstack_dashboard/dashboards/project/vg_snapshots/views.py @@ -140,10 +140,9 @@ class CreateGroupView(forms.ModalFormView): usages['volumes']['quota']): raise ValueError(_('Unable to create group due to ' 'exceeding volume quota limit.')) - else: - context['numRequestedItems'] = num_volumes - context['usages'] = usages + context['numRequestedItems'] = num_volumes + context['usages'] = usages except ValueError as e: exceptions.handle(self.request, e.message) return None diff --git a/openstack_dashboard/dashboards/project/volume_groups/views.py b/openstack_dashboard/dashboards/project/volume_groups/views.py index 0ec2650..90d008f 100644 --- a/openstack_dashboard/dashboards/project/volume_groups/views.py +++ b/openstack_dashboard/dashboards/project/volume_groups/views.py @@ -207,10 +207,9 @@ class CreateSnapshotView(forms.ModalFormView): usages['snapshots']['quota']): raise ValueError(_('Unable to create snapshots due to ' 'exceeding snapshot quota limit.')) - else: - context['numRequestedItems'] = num_volumes - context['usages'] = usages + context['numRequestedItems'] = num_volumes + context['usages'] = usages except ValueError as e: exceptions.handle(self.request, e.message) return None @@ -251,10 +250,9 @@ class CloneGroupView(forms.ModalFormView): usages['volumes']['quota']): raise ValueError(_('Unable to create group due to ' 'exceeding volume quota limit.')) - else: - context['numRequestedItems'] = num_volumes - context['usages'] = usages + context['numRequestedItems'] = num_volumes + context['usages'] = usages except ValueError as e: exceptions.handle(self.request, e.message) return None diff --git a/openstack_dashboard/dashboards/project/volumes/forms.py b/openstack_dashboard/dashboards/project/volumes/forms.py index 04b6423..ab90e46 100644 --- a/openstack_dashboard/dashboards/project/volumes/forms.py +++ b/openstack_dashboard/dashboards/project/volumes/forms.py @@ -420,7 +420,7 @@ class CreateForm(forms.SelfHandlingForm): params = {'req': data['size'], 'avail': availableGB} raise ValidationError(error_message % params) - elif availableVol <= 0: + if availableVol <= 0: error_message = _('You are already using all of your available' ' volumes.') raise ValidationError(error_message)