Browse Source

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

Change-Id: I81c694c17106c179a53326a12e78cfa899872970
tags/15.0.0.0b2
Akihiro Motoki 5 months ago
parent
commit
59beb951a3

+ 0
- 2
.pylintrc View File

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

+ 2
- 2
horizon/tables/base.py View File

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

+ 3
- 3
horizon/workflows/base.py View File

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

+ 13
- 13
openstack_dashboard/api/neutron.py View File

@@ -687,13 +687,13 @@ class FloatingIpManager(object):
687 687
         else:
688 688
             router_ports = [p for p in ports
689 689
                             if p.device_owner in ROUTER_INTERFACE_OWNERS]
690
-        reachable_subnets = set([p.fixed_ips[0]['subnet_id']
691
-                                 for p in router_ports
692
-                                 if p.device_id in gw_routers])
690
+        reachable_subnets = set(p.fixed_ips[0]['subnet_id']
691
+                                for p in router_ports
692
+                                if p.device_id in gw_routers)
693 693
         # we have to include any shared subnets as well because we may not
694 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)
696
-                      for s in n.subnets])
695
+        shared = set(s.id for n in network_list(self.request, shared=True)
696
+                     for s in n.subnets)
697 697
         return reachable_subnets | shared
698 698
 
699 699
     @profiler.trace
@@ -1012,7 +1012,7 @@ def network_list(request, **params):
1012 1012
     networks = neutronclient(request).list_networks(**params).get('networks')
1013 1013
     # Get subnet list to expand subnet info in network list.
1014 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 1016
     # Expand subnet list from subnet_id to values.
1017 1017
     for n in networks:
1018 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 1328
     if 'tenant_id' in params:
1329 1329
         trunk_filters['tenant_id'] = params['tenant_id']
1330 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 1332
     # Create a dict map for child ports (port ID to trunk info)
1333
-    child_ports = dict([(s['port_id'],
1334
-                         {'trunk_id': t['id'],
1335
-                          'segmentation_type': s['segmentation_type'],
1336
-                          'segmentation_id': s['segmentation_id']})
1337
-                        for t in trunks
1338
-                        for s in t['sub_ports']])
1333
+    child_ports = dict((s['port_id'],
1334
+                        {'trunk_id': t['id'],
1335
+                         'segmentation_type': s['segmentation_type'],
1336
+                         'segmentation_id': s['segmentation_id']})
1337
+                       for t in trunks
1338
+                       for s in t['sub_ports'])
1339 1339
 
1340 1340
     def _get_port_info(port):
1341 1341
         if port['id'] in parent_ports:

+ 2
- 2
openstack_dashboard/dashboards/admin/floating_ips/views.py View File

@@ -85,13 +85,13 @@ class IndexView(tables.DataTableView):
85 85
                 exceptions.handle(
86 86
                     self.request,
87 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 90
             tenants = get_tenant_list(self.request)
91 91
             tenant_dict = OrderedDict([(t.id, t) for t in tenants])
92 92
 
93 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 96
             for ip in floating_ips:
97 97
                 ip.instance_name = instances_dict.get(ip.instance_id)

+ 1
- 1
openstack_dashboard/dashboards/admin/images/views.py View File

@@ -107,7 +107,7 @@ class IndexView(tables.DataTableView):
107 107
                 msg = _('Unable to retrieve project list.')
108 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 112
             for image in images:
113 113
                 image.tenant_name = tenant_dict.get(image.owner)

+ 2
- 2
openstack_dashboard/dashboards/admin/instances/views.py View File

@@ -87,7 +87,7 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView):
87 87
         # Gather our tenants to correlate against IDs
88 88
         try:
89 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 91
         except Exception:
92 92
             msg = _('Unable to retrieve instance project information.')
93 93
             exceptions.handle(self.request, msg)
@@ -112,7 +112,7 @@ class AdminIndexView(tables.PagedTableMixin, tables.DataTableView):
112 112
         # Gather our flavors to correlate against IDs
113 113
         try:
114 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 116
         except Exception:
117 117
             msg = _("Unable to retrieve flavor list.")
118 118
             exceptions.handle(self.request, msg)

+ 2
- 2
openstack_dashboard/dashboards/admin/rbac_policies/views.py View File

@@ -57,7 +57,7 @@ class IndexView(tables.DataTableView):
57 57
             msg = _("Unable to retrieve information about the "
58 58
                     "policies' networks.")
59 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 62
     def _get_qos_policies(self):
63 63
         qos_policies = []
@@ -69,7 +69,7 @@ class IndexView(tables.DataTableView):
69 69
             msg = _("Unable to retrieve information about the "
70 70
                     "policies' qos policies.")
71 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 74
     def get_data(self):
75 75
         try:

+ 1
- 1
openstack_dashboard/dashboards/admin/snapshots/views.py View File

@@ -62,7 +62,7 @@ class SnapshotsView(tables.PagedTableMixin, tables.DataTableView):
62 62
                 msg = _('Unable to retrieve volume project information.')
63 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 66
             for snapshot in snapshots:
67 67
                 volume = volumes.get(snapshot.volume_id)
68 68
                 tenant_id = getattr(volume,

+ 2
- 2
openstack_dashboard/dashboards/project/floating_ips/views.py View File

@@ -110,7 +110,7 @@ class IndexView(tables.DataTableView):
110 110
             floating_ip_pools = []
111 111
             exceptions.handle(self.request,
112 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 115
         attached_instance_ids = [ip.instance_id for ip in floating_ips
116 116
                                  if ip.instance_id is not None]
@@ -126,7 +126,7 @@ class IndexView(tables.DataTableView):
126 126
                 exceptions.handle(self.request,
127 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 131
         for ip in floating_ips:
132 132
             ip.instance_name = instances_dict.get(ip.instance_id)

+ 2
- 2
openstack_dashboard/dashboards/project/instances/views.py View File

@@ -73,7 +73,7 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView):
73 73
         # Gather our flavors to correlate our instances to them
74 74
         try:
75 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 77
         except Exception:
78 78
             exceptions.handle(self.request, ignore=True)
79 79
             return {}
@@ -83,7 +83,7 @@ class IndexView(tables.PagedTableMixin, tables.DataTableView):
83 83
         try:
84 84
             # TODO(gabriel): Handle pagination.
85 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 87
         except Exception:
88 88
             exceptions.handle(self.request, ignore=True)
89 89
             return {}

+ 1
- 1
openstack_dashboard/dashboards/project/volumes/views.py View File

@@ -88,7 +88,7 @@ class VolumeTableMixIn(object):
88 88
                 self.request, search_opts=search_opts)
89 89
             if snapshots:
90 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 92
         except Exception:
93 93
             exceptions.handle(self.request,
94 94
                               _("Unable to retrieve snapshot list."))

Loading…
Cancel
Save