pylint: Fix unnecessary-comprehension warning
'unnecessary-comprehension' warning is emitted when unnecessary use of a comprehension is found. classes attribute in Action can be a tuple, so we need list() to ensure it is a list before adding 'disabled'. I think it is time to introduce a method in Action class or somewhere but it should be handled separately. Change-Id: I16a98d56b6d0bd0af234b00735c6ed576620df7e
This commit is contained in:
parent
692778f8cf
commit
74df97f57c
@ -66,8 +66,6 @@ disable=
|
||||
too-many-locals,
|
||||
too-many-return-statements,
|
||||
too-many-statements,
|
||||
# Better to be fixed but too many hits :(
|
||||
unnecessary-comprehension, # TODO
|
||||
useless-object-inheritance
|
||||
|
||||
[Basic]
|
||||
|
@ -107,7 +107,7 @@ def angular_templates(context):
|
||||
# there will simply be no pre-loaded version for this template.
|
||||
pass
|
||||
|
||||
templates = [(key, value) for key, value in angular_templates.items()]
|
||||
templates = list(angular_templates.items())
|
||||
templates.sort(key=lambda item: item[0])
|
||||
|
||||
return {
|
||||
|
@ -161,7 +161,7 @@ class KeystoneBackend(object):
|
||||
region_name = None
|
||||
id_endpoints = scoped_auth_ref.service_catalog.\
|
||||
get_endpoints(service_type='identity')
|
||||
for id_endpoint in [cat for cat in id_endpoints['identity']]:
|
||||
for id_endpoint in id_endpoints['identity']:
|
||||
if auth_url in id_endpoint.values():
|
||||
region_name = id_endpoint['region']
|
||||
break
|
||||
|
@ -314,7 +314,7 @@ def get_url_for_service(service, region, endpoint_type):
|
||||
# in the current region, it is okay to use the first endpoint for any
|
||||
# identity service endpoints and we can assume that it is global
|
||||
if service['type'] == 'identity' and not available_endpoints:
|
||||
available_endpoints = [endpoint for endpoint in service_endpoints]
|
||||
available_endpoints = service_endpoints
|
||||
|
||||
for endpoint in available_endpoints:
|
||||
try:
|
||||
|
@ -303,8 +303,7 @@ class MetadefsResourceTypesList(generic.View):
|
||||
Any request parameters will be passed through the API as filters.
|
||||
"""
|
||||
return {
|
||||
'items': [resource_type for resource_type in
|
||||
api.glance.metadefs_resource_types_list(request)]
|
||||
'items': api.glance.metadefs_resource_types_list(request)
|
||||
}
|
||||
|
||||
|
||||
|
@ -224,7 +224,8 @@ class Extensions(generic.View):
|
||||
http://localhost/api/neutron/extensions
|
||||
"""
|
||||
result = api.neutron.list_extensions(request)
|
||||
return {'items': [e for e in result]}
|
||||
# list_extensions can return a tuple, so list() is required.
|
||||
return {'items': list(result)}
|
||||
|
||||
|
||||
class DefaultQuotaSets(generic.View):
|
||||
|
@ -309,7 +309,7 @@ class ConsoleOutput(generic.View):
|
||||
log_length = request.DATA.get('length', 100)
|
||||
console_lines = api.nova.server_console_output(request, server_id,
|
||||
tail_length=log_length)
|
||||
return {"lines": [x for x in console_lines.split('\n')]}
|
||||
return {"lines": console_lines.split('\n')}
|
||||
|
||||
|
||||
@urls.register
|
||||
|
@ -114,7 +114,7 @@ class AvailabilityZoneFilterAction(tables.FilterAction):
|
||||
|
||||
|
||||
def get_aggregate_hosts(aggregate):
|
||||
return [host for host in aggregate.hosts]
|
||||
return aggregate.hosts
|
||||
|
||||
|
||||
def get_metadata(aggregate):
|
||||
|
@ -41,7 +41,7 @@ class CreatePort(project_tables.CreatePort):
|
||||
request, tenant_id=tenant_id, targets=('port', ))
|
||||
if usages.get('port', {}).get('available', 1) <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ["disabled"]
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _("Create Port (Quota exceeded)")
|
||||
else:
|
||||
self.verbose_name = _("Create Port")
|
||||
|
@ -53,7 +53,7 @@ class CreateSubnet(proj_tables.SubnetPolicyTargetMixin, tables.LinkAction):
|
||||
# usages["subnet'] is empty
|
||||
if usages.get('subnet', {}).get('available', 1) <= 0:
|
||||
if 'disabled' not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _('Create Subnet (Quota exceeded)')
|
||||
else:
|
||||
self.verbose_name = _('Create Subnet')
|
||||
|
@ -59,7 +59,7 @@ class CreateSubnet(project_tables.CreateSubnet):
|
||||
# usages["subnet'] is empty
|
||||
if usages.get('subnet', {}).get('available', 1) <= 0:
|
||||
if 'disabled' not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _('Create Subnet (Quota exceeded)')
|
||||
else:
|
||||
self.verbose_name = _('Create Subnet')
|
||||
|
@ -51,7 +51,7 @@ class AllocateIP(tables.LinkAction):
|
||||
targets=('floatingip', ))
|
||||
if 'floatingip' in usages and usages['floatingip']['available'] <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = format_lazy(
|
||||
'{verbose_name} {quota_exceeded}',
|
||||
verbose_name=self.verbose_name,
|
||||
|
@ -447,7 +447,7 @@ class LaunchLink(tables.LinkAction):
|
||||
if instances_available <= 0 or cores_available <= 0 \
|
||||
or ram_available <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = format_lazy(
|
||||
'{verbose_name} {quota_exceeded}',
|
||||
verbose_name=self.verbose_name,
|
||||
|
@ -57,7 +57,7 @@ class QuotaKeypairMixin(object):
|
||||
usages.tally('key_pairs', len(self.table.data))
|
||||
if usages['key_pairs']['available'] <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = format_lazy(
|
||||
'{verbose_name} {quota_exceeded}',
|
||||
verbose_name=self.verbose_name,
|
||||
|
@ -91,7 +91,7 @@ class CreatePort(tables.LinkAction):
|
||||
# usages["port"] is empty
|
||||
if usages.get('port', {}).get('available', 1) <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ["disabled"]
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _("Create Port (Quota exceeded)")
|
||||
else:
|
||||
# If the port is deleted, the usage of port will less than
|
||||
|
@ -111,7 +111,7 @@ class CreateSubnet(SubnetPolicyTargetMixin, tables.LinkAction):
|
||||
# usages["subnet'] is empty
|
||||
if usages.get('subnet', {}).get('available', 1) <= 0:
|
||||
if 'disabled' not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _('Create Subnet (Quota exceeded)')
|
||||
else:
|
||||
self.verbose_name = _('Create Subnet')
|
||||
|
@ -93,7 +93,7 @@ class CreateNetwork(tables.LinkAction):
|
||||
# usages["network"] is empty
|
||||
if usages.get('network', {}).get('available', 1) <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ["disabled"]
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _("Create Network (Quota exceeded)")
|
||||
else:
|
||||
self.verbose_name = _("Create Network")
|
||||
@ -135,7 +135,7 @@ class CreateSubnet(subnet_tables.SubnetPolicyTargetMixin, tables.LinkAction):
|
||||
# usages["subnet'] is empty
|
||||
if usages.get('subnet', {}).get('available', 1) <= 0:
|
||||
if 'disabled' not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _('Create Subnet (Quota exceeded)')
|
||||
else:
|
||||
self.verbose_name = _('Create Subnet')
|
||||
|
@ -89,7 +89,7 @@ class CreateRouter(tables.LinkAction):
|
||||
# usages['router'] is empty
|
||||
if usages.get('router', {}).get('available', 1) <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ["disabled"]
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _("Create Router (Quota exceeded)")
|
||||
else:
|
||||
self.verbose_name = _("Create Router")
|
||||
|
@ -70,7 +70,7 @@ class CreateGroup(tables.LinkAction):
|
||||
targets=('security_group', ))
|
||||
if usages['security_group'].get('available', 1) <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ["disabled"]
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = _("Create Security Group (Quota exceeded)")
|
||||
else:
|
||||
self.verbose_name = _("Create Security Group")
|
||||
|
@ -152,7 +152,7 @@ class CreateVolume(tables.LinkAction):
|
||||
|
||||
if gb_available <= 0 or volumes_available <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = format_lazy(
|
||||
'{verbose_name} {quota_exceeded}',
|
||||
verbose_name=self.verbose_name,
|
||||
@ -227,7 +227,7 @@ class CreateSnapshot(VolumePolicyTargetMixin, tables.LinkAction):
|
||||
limits.get('totalSnapshotsUsed', 0))
|
||||
|
||||
if snapshots_available <= 0 and "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = format_lazy(
|
||||
'{verbose_name} {quota_exceeded}',
|
||||
verbose_name=self.verbose_name,
|
||||
@ -315,7 +315,7 @@ class AcceptTransfer(tables.LinkAction):
|
||||
volumes_available = usages['volumes']['available']
|
||||
if gb_available <= 0 or volumes_available <= 0:
|
||||
if "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.classes = list(self.classes) + ['disabled']
|
||||
self.verbose_name = format_lazy(
|
||||
'{verbose_name} {quota_exceeded}',
|
||||
verbose_name=self.verbose_name,
|
||||
|
Loading…
Reference in New Issue
Block a user