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

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

Change-Id: Idb93835f2312625d649231c1baa2a3c566096825
This commit is contained in:
Brian Haley 2019-02-20 14:44:04 -05:00 committed by Slawek Kaplonski
parent c7ab5b8729
commit 8e4f625da6
5 changed files with 18 additions and 20 deletions

View File

@ -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

View File

@ -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')

View File

@ -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

View File

@ -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

View File

@ -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()