From a741998bff925360e2d6a72b5ab53c38779f170a Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Fri, 16 Sep 2016 13:31:35 -0700 Subject: [PATCH] Turn on F812 check F812 list comprehension redefines from line ... While the current violations were benign, this sort of code can easily lead to subtle bugs. Seems worth checking, especially given how cheap it is to bring existing code in line with it. Change-Id: Ibdcf9f93b85a1f1411198001df6bdbfa8f92d114 --- bin/swift-account-audit | 2 +- swift/common/middleware/x_profile/html_viewer.py | 2 +- test/probe/test_container_merge_policy_index.py | 9 ++++----- test/unit/proxy/controllers/test_obj.py | 4 ++-- tox.ini | 3 +-- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/bin/swift-account-audit b/bin/swift-account-audit index c0d82c70ed..7e91ae312d 100755 --- a/bin/swift-account-audit +++ b/bin/swift-account-audit @@ -266,7 +266,7 @@ class Auditor(object): responses[node_id][1].extend(results) if results: marker = results[-1]['name'] - headers = [resp[0] for resp in responses.values()] + headers = [r[0] for r in responses.values()] cont_counts = [int(header['x-account-container-count']) for header in headers] if len(set(cont_counts)) != 1: diff --git a/swift/common/middleware/x_profile/html_viewer.py b/swift/common/middleware/x_profile/html_viewer.py index 85426a93c0..90a5ab876e 100644 --- a/swift/common/middleware/x_profile/html_viewer.py +++ b/swift/common/middleware/x_profile/html_viewer.py @@ -412,7 +412,7 @@ class HTMLViewer(object): nfls.append(func[2]) performance.append(metric[metric_selected]) y_pos = range(len(nfls)) - error = [random.random() for __ in y_pos] + error = [random.random() for _unused in y_pos] plt.clf() if plot_type == 'pie': plt.pie(x=performance, explode=None, labels=nfls, diff --git a/test/probe/test_container_merge_policy_index.py b/test/probe/test_container_merge_policy_index.py index cd60e6dead..0b90852304 100644 --- a/test/probe/test_container_merge_policy_index.py +++ b/test/probe/test_container_merge_policy_index.py @@ -392,11 +392,10 @@ class TestContainerMergePolicyIndex(ReplProbeTest): # at this point two primaries have old policy container_part, container_nodes = self.container_ring.get_nodes( self.account, self.container_name) - head_responses = [] - for node in container_nodes: - metadata = direct_client.direct_head_container( - node, container_part, self.account, self.container_name) - head_responses.append((node, metadata)) + head_responses = [ + (node, direct_client.direct_head_container( + node, container_part, self.account, self.container_name)) + for node in container_nodes] old_container_node_ids = [ node['id'] for node, metadata in head_responses if int(old_policy) == diff --git a/test/unit/proxy/controllers/test_obj.py b/test/unit/proxy/controllers/test_obj.py index bec610c5a6..dd4b24862f 100755 --- a/test/unit/proxy/controllers/test_obj.py +++ b/test/unit/proxy/controllers/test_obj.py @@ -2209,8 +2209,8 @@ class TestECObjController(BaseObjectControllerMixin, unittest.TestCase): fragment_payloads.append(fragments) # join up the fragment payloads per node - ec_archive_bodies = [''.join(fragments) - for fragments in zip(*fragment_payloads)] + ec_archive_bodies = [''.join(frags) + for frags in zip(*fragment_payloads)] return ec_archive_bodies def _make_ec_object_stub(self, test_body=None, policy=None): diff --git a/tox.ini b/tox.ini index a30a3bd58e..de7e2c0b94 100644 --- a/tox.ini +++ b/tox.ini @@ -98,7 +98,6 @@ commands = bandit -c bandit.yaml -r swift bin -n 5 -p gate [flake8] # it's not a bug that we aren't using all of hacking, ignore: -# F812: list comprehension redefines ... # H101: Use TODO(NAME) # H202: assertRaises Exception too broad # H233: Python 3.x incompatible use of print operator @@ -109,7 +108,7 @@ commands = bandit -c bandit.yaml -r swift bin -n 5 -p gate # H404: multi line docstring should start without a leading new line # H405: multi line docstring summary not separated with an empty line # H501: Do not use self.__dict__ for string formatting -ignore = F812,H101,H202,H301,H306,H401,H403,H404,H405,H501 +ignore = H101,H202,H301,H306,H401,H403,H404,H405,H501 exclude = .venv,.tox,dist,*egg filename = *.py,bin/* show-source = True