Browse Source

Fix pylint R1717 (consider-using-dict-comprehension) refactor messages

Don't create an intermediate list before creating a dict.

Change-Id: Idb93835f2312625d649231c1baa2a3c566096825
Brian Haley 1 month ago
parent
commit
8e4f625da6

+ 0
- 1
.pylintrc View File

@@ -87,7 +87,6 @@ disable=
87 87
  too-many-return-statements,
88 88
  too-many-statements,
89 89
 # new for python3 version of pylint
90
- consider-using-dict-comprehension,
91 90
  consider-using-set-comprehension,
92 91
  unnecessary-pass,
93 92
  useless-object-inheritance

+ 3
- 3
neutron/agent/l3/router_info.py View File

@@ -1189,8 +1189,8 @@ class RouterInfo(object):
1189 1189
 
1190 1190
         # Update ex_gw_port on the router info cache
1191 1191
         self.ex_gw_port = self.get_ex_gw_port()
1192
-        self.fip_map = dict([(fip['floating_ip_address'],
1193
-                              fip['fixed_ip_address'])
1194
-                             for fip in self.get_floating_ips()])
1192
+        self.fip_map = dict((fip['floating_ip_address'],
1193
+                             fip['fixed_ip_address'])
1194
+                            for fip in self.get_floating_ips())
1195 1195
         self.fip_managed_by_port_forwardings = self.router.get(
1196 1196
             'fip_managed_by_port_forwardings')

+ 5
- 5
neutron/tests/unit/agent/dhcp/test_agent.py View File

@@ -308,9 +308,9 @@ class TestDhcpAgent(base.BaseTestCase):
308 308
         with mock.patch(DEVICE_MANAGER):
309 309
             dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
310 310
             attrs_to_mock = dict(
311
-                [(a, mock.DEFAULT) for a in
312
-                 ['periodic_resync', 'start_ready_ports_loop',
313
-                  '_process_loop']])
311
+                (a, mock.DEFAULT) for a in
312
+                ['periodic_resync', 'start_ready_ports_loop',
313
+                 '_process_loop'])
314 314
             with mock.patch.multiple(dhcp, **attrs_to_mock) as mocks:
315 315
                 with mock.patch.object(dhcp_agent.eventlet,
316 316
                                        'spawn_n') as spawn_n:
@@ -380,9 +380,9 @@ class TestDhcpAgent(base.BaseTestCase):
380 380
 
381 381
             dhcp = dhcp_agent.DhcpAgent(HOSTNAME)
382 382
 
383
-            attrs_to_mock = dict([(a, mock.DEFAULT)
383
+            attrs_to_mock = dict((a, mock.DEFAULT)
384 384
                                  for a in ['disable_dhcp_helper', 'cache',
385
-                                           'safe_configure_dhcp_for_network']])
385
+                                           'safe_configure_dhcp_for_network'])
386 386
 
387 387
             with mock.patch.multiple(dhcp, **attrs_to_mock) as mocks:
388 388
                 mocks['cache'].get_network_ids.return_value = known_net_ids

+ 3
- 3
neutron/tests/unit/agent/l3/test_agent.py View File

@@ -1730,9 +1730,9 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework):
1730 1730
         p = ri.external_gateway_nat_fip_rules
1731 1731
         s = ri.external_gateway_nat_snat_rules
1732 1732
         attrs_to_mock = dict(
1733
-            [(a, mock.DEFAULT) for a in
1734
-                ['external_gateway_nat_fip_rules',
1735
-                 'external_gateway_nat_snat_rules']]
1733
+            (a, mock.DEFAULT) for a in
1734
+            ['external_gateway_nat_fip_rules',
1735
+             'external_gateway_nat_snat_rules']
1736 1736
         )
1737 1737
         with mock.patch.multiple(ri, **attrs_to_mock) as mocks:
1738 1738
             mocks['external_gateway_nat_fip_rules'].side_effect = p

+ 7
- 8
neutron/tests/unit/agent/linux/test_dhcp.py View File

@@ -1134,8 +1134,7 @@ class TestDhcpLocalProcess(TestBase):
1134 1134
     @mock.patch.object(fileutils, 'ensure_tree')
1135 1135
     def test_enable(self, ensure_dir):
1136 1136
         attrs_to_mock = dict(
1137
-            [(a, mock.DEFAULT) for a in
1138
-                ['active', 'interface_name']]
1137
+            (a, mock.DEFAULT) for a in ['active', 'interface_name']
1139 1138
         )
1140 1139
 
1141 1140
         with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks:
@@ -1158,8 +1157,8 @@ class TestDhcpLocalProcess(TestBase):
1158 1157
         self.assertTrue(self.external_process().disable.called)
1159 1158
 
1160 1159
     def test_disable_not_active(self):
1161
-        attrs_to_mock = dict([(a, mock.DEFAULT) for a in
1162
-                              ['active', 'interface_name']])
1160
+        attrs_to_mock = dict((a, mock.DEFAULT) for a in
1161
+                             ['active', 'interface_name'])
1163 1162
         with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks:
1164 1163
             mocks['active'].__get__ = mock.Mock(return_value=False)
1165 1164
             mocks['interface_name'].__get__ = mock.Mock(return_value='tap0')
@@ -1176,8 +1175,8 @@ class TestDhcpLocalProcess(TestBase):
1176 1175
         delete_ns.assert_called_with('qdhcp-ns')
1177 1176
 
1178 1177
     def test_disable_retain_port(self):
1179
-        attrs_to_mock = dict([(a, mock.DEFAULT) for a in
1180
-                              ['active', 'interface_name']])
1178
+        attrs_to_mock = dict((a, mock.DEFAULT) for a in
1179
+                             ['active', 'interface_name'])
1181 1180
         network = FakeDualNetwork()
1182 1181
         with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks:
1183 1182
             mocks['active'].__get__ = mock.Mock(return_value=True)
@@ -1318,8 +1317,8 @@ class TestDnsmasq(TestBase):
1318 1317
         self.execute.return_value = ('', '')
1319 1318
 
1320 1319
         attrs_to_mock = dict(
1321
-            [(a, mock.DEFAULT) for a in
1322
-                ['_output_opts_file', 'get_conf_file_name', 'interface_name']]
1320
+            (a, mock.DEFAULT) for a in
1321
+            ['_output_opts_file', 'get_conf_file_name', 'interface_name']
1323 1322
         )
1324 1323
 
1325 1324
         test_pm = mock.Mock()

Loading…
Cancel
Save