pylint: Fix consider-using-(dict|set)-comprehension

Change-Id: I81c694c17106c179a53326a12e78cfa899872970
This commit is contained in:
Akihiro Motoki 2018-12-01 22:29:54 +09:00
parent 220b1346bd
commit 59beb951a3
12 changed files with 31 additions and 33 deletions

View File

@ -79,9 +79,7 @@ disable=
# "R" Refactor recommendations
chained-comparison,
comparison-with-itself,
consider-using-dict-comprehension,
consider-using-in,
consider-using-set-comprehension,
cyclic-import, # TODO
duplicate-code,
inconsistent-return-statements, # TODO

View File

@ -653,8 +653,8 @@ class Row(html.HTMLElement):
def status(self):
column_names = self.table._meta.status_columns
if column_names:
statuses = dict([(column_name, self.cells[column_name].status) for
column_name in column_names])
statuses = dict((column_name, self.cells[column_name].status) for
column_name in column_names)
return self.table.calculate_row_status(statuses)
@property

View File

@ -676,9 +676,9 @@ class Workflow(html.HTMLElement):
# registered and ordered.
self.context = WorkflowContext(self)
context_seed = context_seed or {}
clean_seed = dict([(key, val)
for key, val in context_seed.items()
if key in self.contributions | self.depends_on])
clean_seed = dict((key, val)
for key, val in context_seed.items()
if key in self.contributions | self.depends_on)
self.context_seed = clean_seed
self.context.update(clean_seed)

View File

@ -687,13 +687,13 @@ class FloatingIpManager(object):
else:
router_ports = [p for p in ports
if p.device_owner in ROUTER_INTERFACE_OWNERS]
reachable_subnets = set([p.fixed_ips[0]['subnet_id']
for p in router_ports
if p.device_id in gw_routers])
reachable_subnets = set(p.fixed_ips[0]['subnet_id']
for p in router_ports
if p.device_id in gw_routers)
# we have to include any shared subnets as well because we may not
# have permission to see the router interface to infer connectivity
shared = set([s.id for n in network_list(self.request, shared=True)
for s in n.subnets])
shared = set(s.id for n in network_list(self.request, shared=True)
for s in n.subnets)
return reachable_subnets | shared
@profiler.trace
@ -1012,7 +1012,7 @@ def network_list(request, **params):
networks = neutronclient(request).list_networks(**params).get('networks')
# Get subnet list to expand subnet info in network list.
subnets = subnet_list(request)
subnet_dict = dict([(s['id'], s) for s in subnets])
subnet_dict = dict((s['id'], s) for s in subnets)
# Expand subnet list from subnet_id to values.
for n in networks:
# Due to potential timing issues, we can't assume the subnet_dict data
@ -1328,14 +1328,14 @@ def port_list_with_trunk_types(request, **params):
if 'tenant_id' in params:
trunk_filters['tenant_id'] = params['tenant_id']
trunks = neutronclient(request).list_trunks(**trunk_filters)['trunks']
parent_ports = set([t['port_id'] for t in trunks])
parent_ports = set(t['port_id'] for t in trunks)
# Create a dict map for child ports (port ID to trunk info)
child_ports = dict([(s['port_id'],
{'trunk_id': t['id'],
'segmentation_type': s['segmentation_type'],
'segmentation_id': s['segmentation_id']})
for t in trunks
for s in t['sub_ports']])
child_ports = dict((s['port_id'],
{'trunk_id': t['id'],
'segmentation_type': s['segmentation_type'],
'segmentation_id': s['segmentation_id']})
for t in trunks
for s in t['sub_ports'])
def _get_port_info(port):
if port['id'] in parent_ports:

View File

@ -85,13 +85,13 @@ class IndexView(tables.DataTableView):
exceptions.handle(
self.request,
_('Unable to retrieve instance list.'))
instances_dict = dict([(obj.id, obj.name) for obj in instances])
instances_dict = dict((obj.id, obj.name) for obj in instances)
tenants = get_tenant_list(self.request)
tenant_dict = OrderedDict([(t.id, t) for t in tenants])
pools = get_floatingip_pools(self.request)
pool_dict = dict([(obj.id, obj.name) for obj in pools])
pool_dict = dict((obj.id, obj.name) for obj in pools)
for ip in floating_ips:
ip.instance_name = instances_dict.get(ip.instance_id)

View File

@ -107,7 +107,7 @@ class IndexView(tables.DataTableView):
msg = _('Unable to retrieve project list.')
exceptions.handle(self.request, msg)
tenant_dict = dict([(t.id, t.name) for t in tenants])
tenant_dict = dict((t.id, t.name) for t in tenants)
for image in images:
image.tenant_name = tenant_dict.get(image.owner)

View File

@ -87,7 +87,7 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView):
# Gather our tenants to correlate against IDs
try:
tenants, __ = api.keystone.tenant_list(self.request)
return dict([(t.id, t) for t in tenants])
return dict((t.id, t) for t in tenants)
except Exception:
msg = _('Unable to retrieve instance project information.')
exceptions.handle(self.request, msg)
@ -112,7 +112,7 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView):
# Gather our flavors to correlate against IDs
try:
flavors = api.nova.flavor_list(self.request)
return dict([(str(flavor.id), flavor) for flavor in flavors])
return dict((str(flavor.id), flavor) for flavor in flavors)
except Exception:
msg = _("Unable to retrieve flavor list.")
exceptions.handle(self.request, msg)

View File

@ -57,7 +57,7 @@ class IndexView(tables.DataTableView):
msg = _("Unable to retrieve information about the "
"policies' networks.")
exceptions.handle(self.request, msg)
return dict([(n.id, n.name) for n in networks])
return dict((n.id, n.name) for n in networks)
def _get_qos_policies(self):
qos_policies = []
@ -69,7 +69,7 @@ class IndexView(tables.DataTableView):
msg = _("Unable to retrieve information about the "
"policies' qos policies.")
exceptions.handle(self.request, msg)
return dict([(q.id, q.name) for q in qos_policies])
return dict((q.id, q.name) for q in qos_policies)
def get_data(self):
try:

View File

@ -62,7 +62,7 @@ class SnapshotsView(tables.PagedTableMixin, tables.DataTableView):
msg = _('Unable to retrieve volume project information.')
exceptions.handle(self.request, msg)
tenant_dict = dict([(t.id, t) for t in tenants])
tenant_dict = dict((t.id, t) for t in tenants)
for snapshot in snapshots:
volume = volumes.get(snapshot.volume_id)
tenant_id = getattr(volume,

View File

@ -110,7 +110,7 @@ class IndexView(tables.DataTableView):
floating_ip_pools = []
exceptions.handle(self.request,
_('Unable to retrieve floating IP pools.'))
pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools])
pool_dict = dict((obj.id, obj.name) for obj in floating_ip_pools)
attached_instance_ids = [ip.instance_id for ip in floating_ips
if ip.instance_id is not None]
@ -126,7 +126,7 @@ class IndexView(tables.DataTableView):
exceptions.handle(self.request,
_('Unable to retrieve instance list.'))
instances_dict = dict([(obj.id, obj.name) for obj in instances])
instances_dict = dict((obj.id, obj.name) for obj in instances)
for ip in floating_ips:
ip.instance_name = instances_dict.get(ip.instance_id)

View File

@ -73,7 +73,7 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView):
# Gather our flavors to correlate our instances to them
try:
flavors = api.nova.flavor_list(self.request)
return dict([(str(flavor.id), flavor) for flavor in flavors])
return dict((str(flavor.id), flavor) for flavor in flavors)
except Exception:
exceptions.handle(self.request, ignore=True)
return {}
@ -83,7 +83,7 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView):
try:
# TODO(gabriel): Handle pagination.
images = api.glance.image_list_detailed(self.request)[0]
return dict([(str(image.id), image) for image in images])
return dict((str(image.id), image) for image in images)
except Exception:
exceptions.handle(self.request, ignore=True)
return {}

View File

@ -88,7 +88,7 @@ class VolumeTableMixIn(object):
self.request, search_opts=search_opts)
if snapshots:
# extract out the volume ids
volume_ids = set([(s.volume_id) for s in snapshots])
volume_ids = set(s.volume_id for s in snapshots)
except Exception:
exceptions.handle(self.request,
_("Unable to retrieve snapshot list."))