From 8e4f625da69d128465178a51488044e9551be1be Mon Sep 17 00:00:00 2001 From: Brian Haley Date: Wed, 20 Feb 2019 14:44:04 -0500 Subject: [PATCH] Fix pylint R1717 (consider-using-dict-comprehension) refactor messages Don't create an intermediate list before creating a dict. Change-Id: Idb93835f2312625d649231c1baa2a3c566096825 --- .pylintrc | 1 - neutron/agent/l3/router_info.py | 6 +++--- neutron/tests/unit/agent/dhcp/test_agent.py | 10 +++++----- neutron/tests/unit/agent/l3/test_agent.py | 6 +++--- neutron/tests/unit/agent/linux/test_dhcp.py | 15 +++++++-------- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.pylintrc b/.pylintrc index 13b15540751..e4ee68d077c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -87,7 +87,6 @@ disable= too-many-return-statements, too-many-statements, # new for python3 version of pylint - consider-using-dict-comprehension, consider-using-set-comprehension, unnecessary-pass, useless-object-inheritance diff --git a/neutron/agent/l3/router_info.py b/neutron/agent/l3/router_info.py index 38a459f3bcf..1d1b412b753 100644 --- a/neutron/agent/l3/router_info.py +++ b/neutron/agent/l3/router_info.py @@ -1189,8 +1189,8 @@ class RouterInfo(object): # Update ex_gw_port on the router info cache self.ex_gw_port = self.get_ex_gw_port() - self.fip_map = dict([(fip['floating_ip_address'], - fip['fixed_ip_address']) - for fip in self.get_floating_ips()]) + self.fip_map = dict((fip['floating_ip_address'], + fip['fixed_ip_address']) + for fip in self.get_floating_ips()) self.fip_managed_by_port_forwardings = self.router.get( 'fip_managed_by_port_forwardings') diff --git a/neutron/tests/unit/agent/dhcp/test_agent.py b/neutron/tests/unit/agent/dhcp/test_agent.py index 3b46a3a070c..a7f5132e8e1 100644 --- a/neutron/tests/unit/agent/dhcp/test_agent.py +++ b/neutron/tests/unit/agent/dhcp/test_agent.py @@ -308,9 +308,9 @@ class TestDhcpAgent(base.BaseTestCase): with mock.patch(DEVICE_MANAGER): dhcp = dhcp_agent.DhcpAgent(HOSTNAME) attrs_to_mock = dict( - [(a, mock.DEFAULT) for a in - ['periodic_resync', 'start_ready_ports_loop', - '_process_loop']]) + (a, mock.DEFAULT) for a in + ['periodic_resync', 'start_ready_ports_loop', + '_process_loop']) with mock.patch.multiple(dhcp, **attrs_to_mock) as mocks: with mock.patch.object(dhcp_agent.eventlet, 'spawn_n') as spawn_n: @@ -380,9 +380,9 @@ class TestDhcpAgent(base.BaseTestCase): dhcp = dhcp_agent.DhcpAgent(HOSTNAME) - attrs_to_mock = dict([(a, mock.DEFAULT) + attrs_to_mock = dict((a, mock.DEFAULT) for a in ['disable_dhcp_helper', 'cache', - 'safe_configure_dhcp_for_network']]) + 'safe_configure_dhcp_for_network']) with mock.patch.multiple(dhcp, **attrs_to_mock) as mocks: mocks['cache'].get_network_ids.return_value = known_net_ids diff --git a/neutron/tests/unit/agent/l3/test_agent.py b/neutron/tests/unit/agent/l3/test_agent.py index 752b4c35742..755a6fff774 100644 --- a/neutron/tests/unit/agent/l3/test_agent.py +++ b/neutron/tests/unit/agent/l3/test_agent.py @@ -1730,9 +1730,9 @@ class TestBasicRouterOperations(BasicRouterOperationsFramework): p = ri.external_gateway_nat_fip_rules s = ri.external_gateway_nat_snat_rules attrs_to_mock = dict( - [(a, mock.DEFAULT) for a in - ['external_gateway_nat_fip_rules', - 'external_gateway_nat_snat_rules']] + (a, mock.DEFAULT) for a in + ['external_gateway_nat_fip_rules', + 'external_gateway_nat_snat_rules'] ) with mock.patch.multiple(ri, **attrs_to_mock) as mocks: mocks['external_gateway_nat_fip_rules'].side_effect = p diff --git a/neutron/tests/unit/agent/linux/test_dhcp.py b/neutron/tests/unit/agent/linux/test_dhcp.py index b4a7e8bb12a..5c55866afdb 100644 --- a/neutron/tests/unit/agent/linux/test_dhcp.py +++ b/neutron/tests/unit/agent/linux/test_dhcp.py @@ -1134,8 +1134,7 @@ class TestDhcpLocalProcess(TestBase): @mock.patch.object(fileutils, 'ensure_tree') def test_enable(self, ensure_dir): attrs_to_mock = dict( - [(a, mock.DEFAULT) for a in - ['active', 'interface_name']] + (a, mock.DEFAULT) for a in ['active', 'interface_name'] ) with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks: @@ -1158,8 +1157,8 @@ class TestDhcpLocalProcess(TestBase): self.assertTrue(self.external_process().disable.called) def test_disable_not_active(self): - attrs_to_mock = dict([(a, mock.DEFAULT) for a in - ['active', 'interface_name']]) + attrs_to_mock = dict((a, mock.DEFAULT) for a in + ['active', 'interface_name']) with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks: mocks['active'].__get__ = mock.Mock(return_value=False) mocks['interface_name'].__get__ = mock.Mock(return_value='tap0') @@ -1176,8 +1175,8 @@ class TestDhcpLocalProcess(TestBase): delete_ns.assert_called_with('qdhcp-ns') def test_disable_retain_port(self): - attrs_to_mock = dict([(a, mock.DEFAULT) for a in - ['active', 'interface_name']]) + attrs_to_mock = dict((a, mock.DEFAULT) for a in + ['active', 'interface_name']) network = FakeDualNetwork() with mock.patch.multiple(LocalChild, **attrs_to_mock) as mocks: mocks['active'].__get__ = mock.Mock(return_value=True) @@ -1318,8 +1317,8 @@ class TestDnsmasq(TestBase): self.execute.return_value = ('', '') attrs_to_mock = dict( - [(a, mock.DEFAULT) for a in - ['_output_opts_file', 'get_conf_file_name', 'interface_name']] + (a, mock.DEFAULT) for a in + ['_output_opts_file', 'get_conf_file_name', 'interface_name'] ) test_pm = mock.Mock()