Merge "pylint: fix len-as-condition warning"

This commit is contained in:
Zuul 2019-01-16 14:25:39 +00:00 committed by Gerrit Code Review
commit c9536342c2
23 changed files with 32 additions and 36 deletions

View File

@ -45,7 +45,6 @@ disable=
expression-not-assigned,
global-statement,
invalid-name,
len-as-condition,
line-too-long,
misplaced-comparison-constant,
missing-docstring,

View File

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

View File

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

View File

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

View File

@ -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 += "</%s>" % tag
return

View File

@ -904,7 +904,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."))

View File

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

View File

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

View File

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

View File

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

View File

@ -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']

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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