summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkihiro Motoki <amotoki@gmail.com>2018-12-01 22:29:54 +0900
committerAkihiro Motoki <amotoki@gmail.com>2019-01-13 00:59:05 +0900
commit59beb951a3cfb38048ad96d884cd8dcb16081a91 (patch)
tree0e6040afa7383c957b2d9d087de716441b9f9d9c
parent220b1346bdfe88d47adb475f48f4a4e96c60560e (diff)
pylint: Fix consider-using-(dict|set)-comprehension
Notes
Notes (review): Code-Review+2: Ivan Kolodyazhny <e0ne@e0ne.info> Workflow+1: Ivan Kolodyazhny <e0ne@e0ne.info> Code-Review+1: Yongjun Bai <baiyj666@gmail.com> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Mon, 14 Jan 2019 12:48:18 +0000 Reviewed-on: https://review.openstack.org/623653 Project: openstack/horizon Branch: refs/heads/master
-rw-r--r--.pylintrc2
-rw-r--r--horizon/tables/base.py4
-rw-r--r--horizon/workflows/base.py6
-rw-r--r--openstack_dashboard/api/neutron.py26
-rw-r--r--openstack_dashboard/dashboards/admin/floating_ips/views.py4
-rw-r--r--openstack_dashboard/dashboards/admin/images/views.py2
-rw-r--r--openstack_dashboard/dashboards/admin/instances/views.py4
-rw-r--r--openstack_dashboard/dashboards/admin/rbac_policies/views.py4
-rw-r--r--openstack_dashboard/dashboards/admin/snapshots/views.py2
-rw-r--r--openstack_dashboard/dashboards/project/floating_ips/views.py4
-rw-r--r--openstack_dashboard/dashboards/project/instances/views.py4
-rw-r--r--openstack_dashboard/dashboards/project/volumes/views.py2
12 files changed, 31 insertions, 33 deletions
diff --git a/.pylintrc b/.pylintrc
index afa5fe2..842e826 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -79,9 +79,7 @@ disable=
79# "R" Refactor recommendations 79# "R" Refactor recommendations
80 chained-comparison, 80 chained-comparison,
81 comparison-with-itself, 81 comparison-with-itself,
82 consider-using-dict-comprehension,
83 consider-using-in, 82 consider-using-in,
84 consider-using-set-comprehension,
85 cyclic-import, # TODO 83 cyclic-import, # TODO
86 duplicate-code, 84 duplicate-code,
87 inconsistent-return-statements, # TODO 85 inconsistent-return-statements, # TODO
diff --git a/horizon/tables/base.py b/horizon/tables/base.py
index f4e4802..2349ab7 100644
--- a/horizon/tables/base.py
+++ b/horizon/tables/base.py
@@ -653,8 +653,8 @@ class Row(html.HTMLElement):
653 def status(self): 653 def status(self):
654 column_names = self.table._meta.status_columns 654 column_names = self.table._meta.status_columns
655 if column_names: 655 if column_names:
656 statuses = dict([(column_name, self.cells[column_name].status) for 656 statuses = dict((column_name, self.cells[column_name].status) for
657 column_name in column_names]) 657 column_name in column_names)
658 return self.table.calculate_row_status(statuses) 658 return self.table.calculate_row_status(statuses)
659 659
660 @property 660 @property
diff --git a/horizon/workflows/base.py b/horizon/workflows/base.py
index 1f814e1..ae39f5e 100644
--- a/horizon/workflows/base.py
+++ b/horizon/workflows/base.py
@@ -676,9 +676,9 @@ class Workflow(html.HTMLElement):
676 # registered and ordered. 676 # registered and ordered.
677 self.context = WorkflowContext(self) 677 self.context = WorkflowContext(self)
678 context_seed = context_seed or {} 678 context_seed = context_seed or {}
679 clean_seed = dict([(key, val) 679 clean_seed = dict((key, val)
680 for key, val in context_seed.items() 680 for key, val in context_seed.items()
681 if key in self.contributions | self.depends_on]) 681 if key in self.contributions | self.depends_on)
682 self.context_seed = clean_seed 682 self.context_seed = clean_seed
683 self.context.update(clean_seed) 683 self.context.update(clean_seed)
684 684
diff --git a/openstack_dashboard/api/neutron.py b/openstack_dashboard/api/neutron.py
index 4220d60..1edc038 100644
--- a/openstack_dashboard/api/neutron.py
+++ b/openstack_dashboard/api/neutron.py
@@ -687,13 +687,13 @@ class FloatingIpManager(object):
687 else: 687 else:
688 router_ports = [p for p in ports 688 router_ports = [p for p in ports
689 if p.device_owner in ROUTER_INTERFACE_OWNERS] 689 if p.device_owner in ROUTER_INTERFACE_OWNERS]
690 reachable_subnets = set([p.fixed_ips[0]['subnet_id'] 690 reachable_subnets = set(p.fixed_ips[0]['subnet_id']
691 for p in router_ports 691 for p in router_ports
692 if p.device_id in gw_routers]) 692 if p.device_id in gw_routers)
693 # we have to include any shared subnets as well because we may not 693 # we have to include any shared subnets as well because we may not
694 # have permission to see the router interface to infer connectivity 694 # have permission to see the router interface to infer connectivity
695 shared = set([s.id for n in network_list(self.request, shared=True) 695 shared = set(s.id for n in network_list(self.request, shared=True)
696 for s in n.subnets]) 696 for s in n.subnets)
697 return reachable_subnets | shared 697 return reachable_subnets | shared
698 698
699 @profiler.trace 699 @profiler.trace
@@ -1012,7 +1012,7 @@ def network_list(request, **params):
1012 networks = neutronclient(request).list_networks(**params).get('networks') 1012 networks = neutronclient(request).list_networks(**params).get('networks')
1013 # Get subnet list to expand subnet info in network list. 1013 # Get subnet list to expand subnet info in network list.
1014 subnets = subnet_list(request) 1014 subnets = subnet_list(request)
1015 subnet_dict = dict([(s['id'], s) for s in subnets]) 1015 subnet_dict = dict((s['id'], s) for s in subnets)
1016 # Expand subnet list from subnet_id to values. 1016 # Expand subnet list from subnet_id to values.
1017 for n in networks: 1017 for n in networks:
1018 # Due to potential timing issues, we can't assume the subnet_dict data 1018 # 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):
1328 if 'tenant_id' in params: 1328 if 'tenant_id' in params:
1329 trunk_filters['tenant_id'] = params['tenant_id'] 1329 trunk_filters['tenant_id'] = params['tenant_id']
1330 trunks = neutronclient(request).list_trunks(**trunk_filters)['trunks'] 1330 trunks = neutronclient(request).list_trunks(**trunk_filters)['trunks']
1331 parent_ports = set([t['port_id'] for t in trunks]) 1331 parent_ports = set(t['port_id'] for t in trunks)
1332 # Create a dict map for child ports (port ID to trunk info) 1332 # Create a dict map for child ports (port ID to trunk info)
1333 child_ports = dict([(s['port_id'], 1333 child_ports = dict((s['port_id'],
1334 {'trunk_id': t['id'], 1334 {'trunk_id': t['id'],
1335 'segmentation_type': s['segmentation_type'], 1335 'segmentation_type': s['segmentation_type'],
1336 'segmentation_id': s['segmentation_id']}) 1336 'segmentation_id': s['segmentation_id']})
1337 for t in trunks 1337 for t in trunks
1338 for s in t['sub_ports']]) 1338 for s in t['sub_ports'])
1339 1339
1340 def _get_port_info(port): 1340 def _get_port_info(port):
1341 if port['id'] in parent_ports: 1341 if port['id'] in parent_ports:
diff --git a/openstack_dashboard/dashboards/admin/floating_ips/views.py b/openstack_dashboard/dashboards/admin/floating_ips/views.py
index 39d5c53..5ec6dd0 100644
--- a/openstack_dashboard/dashboards/admin/floating_ips/views.py
+++ b/openstack_dashboard/dashboards/admin/floating_ips/views.py
@@ -85,13 +85,13 @@ class IndexView(tables.DataTableView):
85 exceptions.handle( 85 exceptions.handle(
86 self.request, 86 self.request,
87 _('Unable to retrieve instance list.')) 87 _('Unable to retrieve instance list.'))
88 instances_dict = dict([(obj.id, obj.name) for obj in instances]) 88 instances_dict = dict((obj.id, obj.name) for obj in instances)
89 89
90 tenants = get_tenant_list(self.request) 90 tenants = get_tenant_list(self.request)
91 tenant_dict = OrderedDict([(t.id, t) for t in tenants]) 91 tenant_dict = OrderedDict([(t.id, t) for t in tenants])
92 92
93 pools = get_floatingip_pools(self.request) 93 pools = get_floatingip_pools(self.request)
94 pool_dict = dict([(obj.id, obj.name) for obj in pools]) 94 pool_dict = dict((obj.id, obj.name) for obj in pools)
95 95
96 for ip in floating_ips: 96 for ip in floating_ips:
97 ip.instance_name = instances_dict.get(ip.instance_id) 97 ip.instance_name = instances_dict.get(ip.instance_id)
diff --git a/openstack_dashboard/dashboards/admin/images/views.py b/openstack_dashboard/dashboards/admin/images/views.py
index a4b9029..ba39744 100644
--- a/openstack_dashboard/dashboards/admin/images/views.py
+++ b/openstack_dashboard/dashboards/admin/images/views.py
@@ -107,7 +107,7 @@ class IndexView(tables.DataTableView):
107 msg = _('Unable to retrieve project list.') 107 msg = _('Unable to retrieve project list.')
108 exceptions.handle(self.request, msg) 108 exceptions.handle(self.request, msg)
109 109
110 tenant_dict = dict([(t.id, t.name) for t in tenants]) 110 tenant_dict = dict((t.id, t.name) for t in tenants)
111 111
112 for image in images: 112 for image in images:
113 image.tenant_name = tenant_dict.get(image.owner) 113 image.tenant_name = tenant_dict.get(image.owner)
diff --git a/openstack_dashboard/dashboards/admin/instances/views.py b/openstack_dashboard/dashboards/admin/instances/views.py
index 488d1c4..006185b 100644
--- a/openstack_dashboard/dashboards/admin/instances/views.py
+++ b/openstack_dashboard/dashboards/admin/instances/views.py
@@ -87,7 +87,7 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView):
87 # Gather our tenants to correlate against IDs 87 # Gather our tenants to correlate against IDs
88 try: 88 try:
89 tenants, __ = api.keystone.tenant_list(self.request) 89 tenants, __ = api.keystone.tenant_list(self.request)
90 return dict([(t.id, t) for t in tenants]) 90 return dict((t.id, t) for t in tenants)
91 except Exception: 91 except Exception:
92 msg = _('Unable to retrieve instance project information.') 92 msg = _('Unable to retrieve instance project information.')
93 exceptions.handle(self.request, msg) 93 exceptions.handle(self.request, msg)
@@ -112,7 +112,7 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView):
112 # Gather our flavors to correlate against IDs 112 # Gather our flavors to correlate against IDs
113 try: 113 try:
114 flavors = api.nova.flavor_list(self.request) 114 flavors = api.nova.flavor_list(self.request)
115 return dict([(str(flavor.id), flavor) for flavor in flavors]) 115 return dict((str(flavor.id), flavor) for flavor in flavors)
116 except Exception: 116 except Exception:
117 msg = _("Unable to retrieve flavor list.") 117 msg = _("Unable to retrieve flavor list.")
118 exceptions.handle(self.request, msg) 118 exceptions.handle(self.request, msg)
diff --git a/openstack_dashboard/dashboards/admin/rbac_policies/views.py b/openstack_dashboard/dashboards/admin/rbac_policies/views.py
index b517aa8..a0adc87 100644
--- a/openstack_dashboard/dashboards/admin/rbac_policies/views.py
+++ b/openstack_dashboard/dashboards/admin/rbac_policies/views.py
@@ -57,7 +57,7 @@ class IndexView(tables.DataTableView):
57 msg = _("Unable to retrieve information about the " 57 msg = _("Unable to retrieve information about the "
58 "policies' networks.") 58 "policies' networks.")
59 exceptions.handle(self.request, msg) 59 exceptions.handle(self.request, msg)
60 return dict([(n.id, n.name) for n in networks]) 60 return dict((n.id, n.name) for n in networks)
61 61
62 def _get_qos_policies(self): 62 def _get_qos_policies(self):
63 qos_policies = [] 63 qos_policies = []
@@ -69,7 +69,7 @@ class IndexView(tables.DataTableView):
69 msg = _("Unable to retrieve information about the " 69 msg = _("Unable to retrieve information about the "
70 "policies' qos policies.") 70 "policies' qos policies.")
71 exceptions.handle(self.request, msg) 71 exceptions.handle(self.request, msg)
72 return dict([(q.id, q.name) for q in qos_policies]) 72 return dict((q.id, q.name) for q in qos_policies)
73 73
74 def get_data(self): 74 def get_data(self):
75 try: 75 try:
diff --git a/openstack_dashboard/dashboards/admin/snapshots/views.py b/openstack_dashboard/dashboards/admin/snapshots/views.py
index 75afb30..9995285 100644
--- a/openstack_dashboard/dashboards/admin/snapshots/views.py
+++ b/openstack_dashboard/dashboards/admin/snapshots/views.py
@@ -62,7 +62,7 @@ class SnapshotsView(tables.PagedTableMixin, tables.DataTableView):
62 msg = _('Unable to retrieve volume project information.') 62 msg = _('Unable to retrieve volume project information.')
63 exceptions.handle(self.request, msg) 63 exceptions.handle(self.request, msg)
64 64
65 tenant_dict = dict([(t.id, t) for t in tenants]) 65 tenant_dict = dict((t.id, t) for t in tenants)
66 for snapshot in snapshots: 66 for snapshot in snapshots:
67 volume = volumes.get(snapshot.volume_id) 67 volume = volumes.get(snapshot.volume_id)
68 tenant_id = getattr(volume, 68 tenant_id = getattr(volume,
diff --git a/openstack_dashboard/dashboards/project/floating_ips/views.py b/openstack_dashboard/dashboards/project/floating_ips/views.py
index d9bfead..affbe28 100644
--- a/openstack_dashboard/dashboards/project/floating_ips/views.py
+++ b/openstack_dashboard/dashboards/project/floating_ips/views.py
@@ -110,7 +110,7 @@ class IndexView(tables.DataTableView):
110 floating_ip_pools = [] 110 floating_ip_pools = []
111 exceptions.handle(self.request, 111 exceptions.handle(self.request,
112 _('Unable to retrieve floating IP pools.')) 112 _('Unable to retrieve floating IP pools.'))
113 pool_dict = dict([(obj.id, obj.name) for obj in floating_ip_pools]) 113 pool_dict = dict((obj.id, obj.name) for obj in floating_ip_pools)
114 114
115 attached_instance_ids = [ip.instance_id for ip in floating_ips 115 attached_instance_ids = [ip.instance_id for ip in floating_ips
116 if ip.instance_id is not None] 116 if ip.instance_id is not None]
@@ -126,7 +126,7 @@ class IndexView(tables.DataTableView):
126 exceptions.handle(self.request, 126 exceptions.handle(self.request,
127 _('Unable to retrieve instance list.')) 127 _('Unable to retrieve instance list.'))
128 128
129 instances_dict = dict([(obj.id, obj.name) for obj in instances]) 129 instances_dict = dict((obj.id, obj.name) for obj in instances)
130 130
131 for ip in floating_ips: 131 for ip in floating_ips:
132 ip.instance_name = instances_dict.get(ip.instance_id) 132 ip.instance_name = instances_dict.get(ip.instance_id)
diff --git a/openstack_dashboard/dashboards/project/instances/views.py b/openstack_dashboard/dashboards/project/instances/views.py
index f17da04..07a105f 100644
--- a/openstack_dashboard/dashboards/project/instances/views.py
+++ b/openstack_dashboard/dashboards/project/instances/views.py
@@ -73,7 +73,7 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView):
73 # Gather our flavors to correlate our instances to them 73 # Gather our flavors to correlate our instances to them
74 try: 74 try:
75 flavors = api.nova.flavor_list(self.request) 75 flavors = api.nova.flavor_list(self.request)
76 return dict([(str(flavor.id), flavor) for flavor in flavors]) 76 return dict((str(flavor.id), flavor) for flavor in flavors)
77 except Exception: 77 except Exception:
78 exceptions.handle(self.request, ignore=True) 78 exceptions.handle(self.request, ignore=True)
79 return {} 79 return {}
@@ -83,7 +83,7 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView):
83 try: 83 try:
84 # TODO(gabriel): Handle pagination. 84 # TODO(gabriel): Handle pagination.
85 images = api.glance.image_list_detailed(self.request)[0] 85 images = api.glance.image_list_detailed(self.request)[0]
86 return dict([(str(image.id), image) for image in images]) 86 return dict((str(image.id), image) for image in images)
87 except Exception: 87 except Exception:
88 exceptions.handle(self.request, ignore=True) 88 exceptions.handle(self.request, ignore=True)
89 return {} 89 return {}
diff --git a/openstack_dashboard/dashboards/project/volumes/views.py b/openstack_dashboard/dashboards/project/volumes/views.py
index 17afcb1..5c68a9e 100644
--- a/openstack_dashboard/dashboards/project/volumes/views.py
+++ b/openstack_dashboard/dashboards/project/volumes/views.py
@@ -88,7 +88,7 @@ class VolumeTableMixIn(object):
88 self.request, search_opts=search_opts) 88 self.request, search_opts=search_opts)
89 if snapshots: 89 if snapshots:
90 # extract out the volume ids 90 # extract out the volume ids
91 volume_ids = set([(s.volume_id) for s in snapshots]) 91 volume_ids = set(s.volume_id for s in snapshots)
92 except Exception: 92 except Exception:
93 exceptions.handle(self.request, 93 exceptions.handle(self.request,
94 _("Unable to retrieve snapshot list.")) 94 _("Unable to retrieve snapshot list."))