diff --git a/.pylintrc b/.pylintrc index 5c0fe878fe..ebafe9b05a 100644 --- a/.pylintrc +++ b/.pylintrc @@ -48,7 +48,6 @@ disable= expression-not-assigned, global-statement, invalid-name, - len-as-condition, line-too-long, misplaced-comparison-constant, missing-docstring, diff --git a/horizon/base.py b/horizon/base.py index 1cf641a30f..28ffe4824a 100644 --- a/horizon/base.py +++ b/horizon/base.py @@ -519,7 +519,7 @@ class Dashboard(Registry, HorizonComponent): panel_groups.append((panel_group.slug, panel_group)) # Deal with leftovers (such as add-on registrations) - if len(registered): + if registered: slugs = [panel.slug for panel in registered.values()] new_group = PanelGroup(self, slug="other", @@ -769,7 +769,7 @@ class Site(Registry, HorizonComponent): dashboard = self._registered(item) dashboards.append(dashboard) registered.pop(dashboard.__class__) - if len(registered): + if registered: extra = sorted(registered.values()) dashboards.extend(extra) return dashboards @@ -785,7 +785,7 @@ class Site(Registry, HorizonComponent): """ if self.default_dashboard: return self._registered(self.default_dashboard) - elif len(self._registry): + elif self._registry: return self.get_dashboards()[0] else: raise NotRegistered("No dashboard modules have been registered.") diff --git a/horizon/middleware/operation_log.py b/horizon/middleware/operation_log.py index 87294f4807..30dde20871 100644 --- a/horizon/middleware/operation_log.py +++ b/horizon/middleware/operation_log.py @@ -182,7 +182,7 @@ class OperationLogMiddleware(object): # when a file uploaded (E.g create image) files = request.FILES.values() - if len(list(files)) > 0: + if list(files): filenames = ', '.join( [up_file.name for up_file in files]) params['file_name'] = filenames diff --git a/horizon/tables/base.py b/horizon/tables/base.py index daf64019e4..f38e85d412 100644 --- a/horizon/tables/base.py +++ b/horizon/tables/base.py @@ -496,7 +496,7 @@ class Column(html.HTMLElement): data = [self.get_raw_data(datum) for datum in self.table.data] data = [raw_data for raw_data in data if raw_data is not None] - if len(data): + if data: try: summation = summation_function(data) for filter_func in self.filters: diff --git a/horizon/utils/babel_extract_angular.py b/horizon/utils/babel_extract_angular.py index cdf4bd5814..eb231ac678 100644 --- a/horizon/utils/babel_extract_angular.py +++ b/horizon/utils/babel_extract_angular.py @@ -123,7 +123,7 @@ class AngularGettextHTMLParser(html_parser.HTMLParser): def handle_endtag(self, tag): if self.in_translate: - if len(self.inner_tags) > 0: + if self.inner_tags: tag = self.inner_tags.pop() self.data += "" % tag return diff --git a/horizon/workflows/base.py b/horizon/workflows/base.py index ae39f5efa4..0b20b20abb 100644 --- a/horizon/workflows/base.py +++ b/horizon/workflows/base.py @@ -905,7 +905,7 @@ class Workflow(html.HTMLElement): def verify_integrity(self): provided_keys = self.contributions | set(self.context_seed.keys()) - if len(self.depends_on - provided_keys): + if self.depends_on - provided_keys: raise exceptions.NotAvailable( _("The current user has insufficient permission to complete " "the requested task.")) diff --git a/openstack_dashboard/api/base.py b/openstack_dashboard/api/base.py index e7d67064aa..00498fc9d6 100644 --- a/openstack_dashboard/api/base.py +++ b/openstack_dashboard/api/base.py @@ -258,7 +258,7 @@ class QuotaSet(Sequence): def get(self, key, default=None): match = [quota for quota in self.items if quota.name == key] - return match.pop() if len(match) else Quota(key, default) + return match.pop() if match else Quota(key, default) def add(self, other): return self.__add__(other) diff --git a/openstack_dashboard/api/keystone.py b/openstack_dashboard/api/keystone.py index 058e1a5f48..0ca69cfcf0 100644 --- a/openstack_dashboard/api/keystone.py +++ b/openstack_dashboard/api/keystone.py @@ -634,7 +634,7 @@ def group_list(request, domain=None, project=None, user=None, filters=None): project_groups = [] for group in groups: roles = roles_for_group(request, group=group.id, project=project) - if roles and len(roles) > 0: + if roles: project_groups.append(group) groups = project_groups return groups diff --git a/openstack_dashboard/api/nova.py b/openstack_dashboard/api/nova.py index 71832345f4..bbea798337 100644 --- a/openstack_dashboard/api/nova.py +++ b/openstack_dashboard/api/nova.py @@ -602,14 +602,14 @@ def server_list_paged(request, servers = [Server(s, request) for s in nova_client.servers.list(detailed, search_opts)] if view_marker == 'possibly_deleted': - if len(servers) == 0: + if not servers: view_marker = 'head_deleted' search_opts['sort_dir'] = 'desc' reversed_order = False servers = [Server(s, request) for s in nova_client.servers.list(detailed, search_opts)] - if len(servers) == 0: + if not servers: view_marker = 'tail_deleted' search_opts['sort_dir'] = 'asc' reversed_order = True diff --git a/openstack_dashboard/api/rest/keystone.py b/openstack_dashboard/api/rest/keystone.py index 8575ae8200..359f63d851 100644 --- a/openstack_dashboard/api/rest/keystone.py +++ b/openstack_dashboard/api/rest/keystone.py @@ -56,7 +56,7 @@ class Users(generic.View): filters = rest_utils.parse_filters_kwargs(request, self.client_keywords)[0] - if len(filters) == 0: + if not filters: filters = None result = api.keystone.user_list( @@ -420,7 +420,7 @@ class Projects(generic.View): filters = rest_utils.parse_filters_kwargs(request, self.client_keywords)[0] - if len(filters) == 0: + if not filters: filters = None paginate = request.GET.get('paginate') == 'true' diff --git a/openstack_dashboard/contrib/developer/profiler/api.py b/openstack_dashboard/contrib/developer/profiler/api.py index 240ca294ae..3d1bcdb9e0 100644 --- a/openstack_dashboard/contrib/developer/profiler/api.py +++ b/openstack_dashboard/contrib/developer/profiler/api.py @@ -89,7 +89,7 @@ def list_traces(request): def get_trace(request, trace_id): def rec(_data, level=0): _data['level'] = level - _data['is_leaf'] = not len(_data['children']) + _data['is_leaf'] = not _data['children'] _data['visible'] = True _data['childrenVisible'] = True finished = _data['info']['finished'] diff --git a/openstack_dashboard/dashboards/admin/info/tables.py b/openstack_dashboard/dashboards/admin/info/tables.py index 9e5b3ef4e4..99a7ece182 100644 --- a/openstack_dashboard/dashboards/admin/info/tables.py +++ b/openstack_dashboard/dashboards/admin/info/tables.py @@ -59,8 +59,7 @@ def show_endpoints(datanum): if 'endpoints' in datanum: template_name = 'admin/info/_cell_endpoints_v2.html' context = None - if (len(datanum['endpoints']) > 0 and - "publicURL" in datanum['endpoints'][0]): + if (datanum['endpoints'] and "publicURL" in datanum['endpoints'][0]): context = datanum['endpoints'][0] else: # this is a keystone v3 version of endpoints diff --git a/openstack_dashboard/dashboards/admin/networks/forms.py b/openstack_dashboard/dashboards/admin/networks/forms.py index 0c4dd5fc32..3796fdca19 100644 --- a/openstack_dashboard/dashboards/admin/networks/forms.py +++ b/openstack_dashboard/dashboards/admin/networks/forms.py @@ -238,7 +238,7 @@ class CreateNetwork(forms.SelfHandlingForm): network_type_choices = [ (net_type, self.provider_types[net_type]['display_name']) for net_type in supported_provider_types] - if len(network_type_choices) == 0: + if not network_type_choices: self._hide_provider_network_type() else: self.fields['network_type'].choices = network_type_choices diff --git a/openstack_dashboard/dashboards/identity/domains/workflows.py b/openstack_dashboard/dashboards/identity/domains/workflows.py index 81bf94b85b..8c518573c7 100644 --- a/openstack_dashboard/dashboards/identity/domains/workflows.py +++ b/openstack_dashboard/dashboards/identity/domains/workflows.py @@ -368,7 +368,7 @@ class UpdateDomain(workflows.Workflow): ] admin_role_ids = [role for role in current_role_ids if role in available_admin_role_ids] - if len(admin_role_ids): + if admin_role_ids: removing_admin = any([role in current_role_ids for role in admin_role_ids]) else: diff --git a/openstack_dashboard/dashboards/identity/groups/views.py b/openstack_dashboard/dashboards/identity/groups/views.py index ef3df9d29d..ba461f8e0b 100644 --- a/openstack_dashboard/dashboards/identity/groups/views.py +++ b/openstack_dashboard/dashboards/identity/groups/views.py @@ -54,8 +54,7 @@ class IndexView(tables.DataTableView): # selected, then search criteria must be provided and # return an empty list filter_first = getattr(settings, 'FILTER_DATA_FIRST', {}) - if filter_first.get('identity.groups', False) \ - and len(filters) == 0: + if filter_first.get('identity.groups', False) and not filters: self._needs_filter_first = True return groups diff --git a/openstack_dashboard/dashboards/identity/projects/views.py b/openstack_dashboard/dashboards/identity/projects/views.py index 74618cc12b..6d3e842e66 100644 --- a/openstack_dashboard/dashboards/identity/projects/views.py +++ b/openstack_dashboard/dashboards/identity/projects/views.py @@ -96,8 +96,7 @@ class IndexView(tables.DataTableView): # selected, then search criteria must be provided and # return an empty list filter_first = getattr(settings, 'FILTER_DATA_FIRST', {}) - if filter_first.get('identity.projects', False) and len( - filters) == 0: + if filter_first.get('identity.projects', False) and not filters: self._needs_filter_first = True self._more = False return tenants diff --git a/openstack_dashboard/dashboards/identity/projects/workflows.py b/openstack_dashboard/dashboards/identity/projects/workflows.py index 0b6e648c5f..837d4f451b 100644 --- a/openstack_dashboard/dashboards/identity/projects/workflows.py +++ b/openstack_dashboard/dashboards/identity/projects/workflows.py @@ -752,7 +752,7 @@ class UpdateProject(workflows.Workflow): if role.name.lower() in _admin_roles] admin_roles = [role for role in current_role_ids if role in available_admin_role_ids] - if len(admin_roles): + if admin_roles: removing_admin = any([role in current_role_ids for role in admin_roles]) else: diff --git a/openstack_dashboard/dashboards/identity/roles/views.py b/openstack_dashboard/dashboards/identity/roles/views.py index eb74b83612..c829dcfb5b 100644 --- a/openstack_dashboard/dashboards/identity/roles/views.py +++ b/openstack_dashboard/dashboards/identity/roles/views.py @@ -52,7 +52,7 @@ class IndexView(tables.DataTableView): # selected, then search criteria must be provided # and return an empty list filter_first = getattr(settings, 'FILTER_DATA_FIRST', {}) - if filter_first.get('identity.roles', False) and len(filters) == 0: + if filter_first.get('identity.roles', False) and not filters: self._needs_filter_first = True return roles diff --git a/openstack_dashboard/dashboards/identity/users/views.py b/openstack_dashboard/dashboards/identity/users/views.py index 576413300f..5199c6e677 100644 --- a/openstack_dashboard/dashboards/identity/users/views.py +++ b/openstack_dashboard/dashboards/identity/users/views.py @@ -68,7 +68,7 @@ class IndexView(tables.DataTableView): # selected, then search criteria must be provided # and return an empty list filter_first = getattr(settings, 'FILTER_DATA_FIRST', {}) - if filter_first.get('identity.users', False) and len(filters) == 0: + if filter_first.get('identity.users', False) and not filters: self._needs_filter_first = True return users diff --git a/openstack_dashboard/dashboards/project/cgroups/forms.py b/openstack_dashboard/dashboards/project/cgroups/forms.py index 2dbd940005..6712da5172 100644 --- a/openstack_dashboard/dashboards/project/cgroups/forms.py +++ b/openstack_dashboard/dashboards/project/cgroups/forms.py @@ -149,7 +149,7 @@ class CreateSnapshotForm(forms.SelfHandlingForm): else: search_opts = {'consistentcygroup_id': data['cgroup_id']} volumes = cinder.volume_list(request, search_opts=search_opts) - if len(volumes) == 0: + if not volumes: msg = _('Unable to create snapshot. Consistency group ' 'must contain volumes.') @@ -208,7 +208,7 @@ class CloneCGroupForm(forms.SelfHandlingForm): search_opts = {'consistentcygroup_id': data['cgroup_id']} volumes = cinder.volume_list(request, search_opts=search_opts) - if len(volumes) == 0: + if not volumes: msg = _('Unable to clone empty consistency group.') exceptions.handle(request, diff --git a/openstack_dashboard/dashboards/project/instances/forms.py b/openstack_dashboard/dashboards/project/instances/forms.py index f3d510a306..ea5cc5f449 100644 --- a/openstack_dashboard/dashboards/project/instances/forms.py +++ b/openstack_dashboard/dashboards/project/instances/forms.py @@ -347,7 +347,7 @@ class AttachInterface(forms.SelfHandlingForm): choices = [('network', _("by Network (and IP address)"))] ports = instance_utils.port_field_data(request, with_network=True) - if len(ports) > 0: + if ports: self.fields['port'].choices = ports choices.append(('port', _("by Port"))) diff --git a/openstack_dashboard/dashboards/project/networks/workflows.py b/openstack_dashboard/dashboards/project/networks/workflows.py index 391d4ce3f9..8a9683c470 100644 --- a/openstack_dashboard/dashboards/project/networks/workflows.py +++ b/openstack_dashboard/dashboards/project/networks/workflows.py @@ -235,10 +235,10 @@ class CreateSubnetInfoAction(workflows.Action): # Populate data-fields for switching the prefixlen field # when user selects a subnetpool other than # "Provider default pool" - for (id, name) in self.fields['subnetpool'].choices: - if not len(id): + for (id_, name) in self.fields['subnetpool'].choices: + if not id_: continue - key = 'data-subnetpool-' + id + key = 'data-subnetpool-' + id_ self.fields['prefixlen'].widget.attrs[key] = \ _('Network Mask') else: @@ -555,9 +555,9 @@ class CreateNetwork(workflows.Workflow): params['gateway_ip'] = None elif data['gateway_ip']: params['gateway_ip'] = data['gateway_ip'] - if 'subnetpool' in data and len(data['subnetpool']): + if 'subnetpool' in data and data['subnetpool']: params['subnetpool_id'] = data['subnetpool'] - if 'prefixlen' in data and len(data['prefixlen']): + if 'prefixlen' in data and data['prefixlen']: params['prefixlen'] = data['prefixlen'] self._setup_subnet_parameters(params, data) diff --git a/openstack_dashboard/dashboards/project/volume_groups/forms.py b/openstack_dashboard/dashboards/project/volume_groups/forms.py index 312bbeb038..d19a99331c 100644 --- a/openstack_dashboard/dashboards/project/volume_groups/forms.py +++ b/openstack_dashboard/dashboards/project/volume_groups/forms.py @@ -136,7 +136,7 @@ class CreateSnapshotForm(forms.SelfHandlingForm): search_opts = {'group_id': group_id} volumes = cinder.volume_list(request, search_opts=search_opts) - if len(volumes) == 0: + if not volumes: msg = _('Unable to create snapshot. ' 'group must contain volumes.') @@ -190,7 +190,7 @@ class CloneGroupForm(forms.SelfHandlingForm): search_opts = {'group_id': group_id} volumes = cinder.volume_list(request, search_opts=search_opts) - if len(volumes) == 0: + if not volumes: msg = _('Unable to clone empty group.') exceptions.handle(request,