From 36db52b630e89d3b0ad26cc747fe59577000ed00 Mon Sep 17 00:00:00 2001 From: DCG-Claude Date: Thu, 1 Oct 2026 09:40:16 -0500 Subject: [PATCH] Merge bitcoin/bitcoin#28194: test: python E721 and flake8 updates bee2d57a655645dbfaf0242e85c5af034023a2fb script: update flake8 to 6.1.0 (Jon Atack) 38c3fd846bff163eb7c50bd77efcdcf8fcbc7f43 test: python E721 updates (Jon Atack) Pull request description: Update our functional tests per [E721](https://www.flake8rules.com/rules/E721.html) enforced by [flake8 6.1.0](https://flake8.pycqa.org/en/latest/release-notes/6.1.0.html), and update our CI lint task to use that release. This makes the following linter output on current master with flake8 6.1.0 green. ``` $ ./test/lint/lint-python.py ; ./test/lint/lint-spelling.py test/functional/p2p_invalid_locator.py:35:16: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` test/functional/test_framework/siphash.py:34:12: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` test/functional/test_framework/siphash.py:64:12: E721 do not compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` src/test/fuzz/descriptor_parse.cpp:88: occurences ==> occurrences ^ Warning: codespell identified likely spelling errors. Any false positives? Add them to the list of ignored words in test/lint/spelling.ignore-words.txt ``` ACKs for top commit: MarcoFalke: lgtm ACK bee2d57a655645dbfaf0242e85c5af034023a2fb Tree-SHA512: f3788a543ca98e44eeeba1d06c32f1b11eec95d4aef068aa1b6b5c401261adfa3fb6c6d6c769f3fe6839d78e74a310d5c926867e7c367d6513a53d580fd376f3 Dash adaptations: - ci/lint/04_install.sh: only the flake8 pin is bumped (5.0.4 -> 6.1.0); the surrounding lines keep Dash's codespell==2.2.1, mypy==0.981 and pyzmq==24.0.1 instead of upstream's context (codespell 2.2.5, mypy 1.4.1, pyzmq 25.1.0 from bitcoin/bitcoin#28009, not backported), because upstream changes only the flake8 line - contrib/containers/ci/ci-slim.Dockerfile: flake8 also bumped 5.0.4 -> 6.1.0; Dash pins the lint Python deps in its CI image too, and 04_install.sh says 'BUMP ALSO contrib/containers/ci/ci-slim.Dockerfile' (and the Dockerfile says the reverse), so the two stay in sync - test/functional/test_framework/crypto/siphash.py: upstream's test_framework/siphash.py changes land at Dash's path test_framework/crypto/siphash.py; content is identical to upstream (git applied them there on its own) --- ci/lint/04_install.sh | 2 +- contrib/containers/ci/ci-slim.Dockerfile | 2 +- src/test/fuzz/descriptor_parse.cpp | 2 +- test/functional/feature_governance.py | 3 +-- test/functional/feature_llmq_connections.py | 11 +++++------ test/functional/feature_llmq_singlenode.py | 3 +-- test/functional/feature_mnehf.py | 3 +-- test/functional/interface_zmq_dash.py | 3 +-- test/functional/p2p_invalid_locator.py | 2 +- test/functional/test_framework/crypto/siphash.py | 4 ++-- 10 files changed, 15 insertions(+), 20 deletions(-) diff --git a/ci/lint/04_install.sh b/ci/lint/04_install.sh index 83010b9b0057..8936b34bfb6b 100755 --- a/ci/lint/04_install.sh +++ b/ci/lint/04_install.sh @@ -34,7 +34,7 @@ python3 --version # NOTE: BUMP ALSO contrib/containers/ci/ci-slim.Dockerfile ${CI_RETRY_EXE} pip3 install \ codespell==2.2.1 \ - flake8==5.0.4 \ + flake8==6.1.0 \ lief==0.13.2 \ mypy==0.981 \ pyzmq==24.0.1 \ diff --git a/contrib/containers/ci/ci-slim.Dockerfile b/contrib/containers/ci/ci-slim.Dockerfile index 73c864983939..eedc49b5d7b6 100644 --- a/contrib/containers/ci/ci-slim.Dockerfile +++ b/contrib/containers/ci/ci-slim.Dockerfile @@ -78,7 +78,7 @@ ENV UV_SYSTEM_PYTHON=1 # NOTE: if versions are changed, update ci/lint/04_install.sh RUN uv pip install --system --break-system-packages \ codespell==2.2.1 \ - flake8==5.0.4 \ + flake8==6.1.0 \ jinja2 \ lief==0.13.2 \ mypy==0.981 \ diff --git a/src/test/fuzz/descriptor_parse.cpp b/src/test/fuzz/descriptor_parse.cpp index 1084c569a703..f93b9b4223c0 100644 --- a/src/test/fuzz/descriptor_parse.cpp +++ b/src/test/fuzz/descriptor_parse.cpp @@ -82,7 +82,7 @@ class MockedDescriptorConverter { std::string desc; desc.reserve(mocked_desc.size()); - // Replace all occurences of '%' followed by two hex characters with the corresponding key. + // Replace all occurrences of '%' followed by two hex characters with the corresponding key. for (size_t i = 0; i < mocked_desc.size();) { if (mocked_desc[i] == '%') { if (i + 3 >= mocked_desc.size()) return {}; diff --git a/test/functional/feature_governance.py b/test/functional/feature_governance.py index f319fd180d9c..4be122f54648 100755 --- a/test/functional/feature_governance.py +++ b/test/functional/feature_governance.py @@ -9,7 +9,6 @@ from test_framework.messages import uint256_to_string from test_framework.test_framework import ( DashTestFramework, - MasternodeInfo, ) from test_framework.governance import have_trigger_for_height, prepare_object from test_framework.util import assert_equal, satoshi_round @@ -195,7 +194,7 @@ def run_test(self): _, mn_payee_protx = height_protx_list[1] payee_idx = None - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: if mn.proTxHash == mn_payee_protx: payee_idx = mn.nodeIdx break diff --git a/test/functional/feature_llmq_connections.py b/test/functional/feature_llmq_connections.py index 9b7955f6b2b5..2a63b912f877 100755 --- a/test/functional/feature_llmq_connections.py +++ b/test/functional/feature_llmq_connections.py @@ -14,7 +14,6 @@ from test_framework.test_framework import ( DashTestFramework, - MasternodeInfo, ) from test_framework.util import assert_greater_than_or_equal @@ -86,7 +85,7 @@ def run_test(self): self.log.info("check that old masternode connections are dropped") removed = False - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: if len(mn.get_node(self).quorum("memberof", mn.proTxHash)) > 0: try: with mn.get_node(self).assert_debug_log(['removing masternodes quorum connections']): @@ -102,7 +101,7 @@ def run_test(self): self.log.info("check that inter-quorum masternode connections are added") added = False - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: if len(mn.get_node(self).quorum("memberof", mn.proTxHash)) > 0: try: with mn.get_node(self).assert_debug_log(['adding mn inter-quorum connections']): @@ -116,11 +115,11 @@ def run_test(self): def check_reconnects(self, expected_connection_count): self.log.info("disable and re-enable networking on all masternodes") - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: mn.get_node(self).setnetworkactive(False) - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: self.wait_until(lambda: len(mn.get_node(self).getpeerinfo()) == 0) - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: mn.get_node(self).setnetworkactive(True) self.bump_mocktime(60) diff --git a/test/functional/feature_llmq_singlenode.py b/test/functional/feature_llmq_singlenode.py index 4e7040b85994..0238ddced9b2 100755 --- a/test/functional/feature_llmq_singlenode.py +++ b/test/functional/feature_llmq_singlenode.py @@ -14,7 +14,6 @@ from test_framework.authproxy import JSONRPCException from test_framework.test_framework import ( DashTestFramework, - MasternodeInfo, ) from test_framework.util import ( assert_raises_rpc_error, @@ -43,7 +42,7 @@ def check_sigs(self, hasrecsigs, isconflicting1, isconflicting2): conflicting_1 = False conflicting_2 = False - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: if mn.get_node(self).quorum("hasrecsig", q_type, id, msgHash): has_sig = True if mn.get_node(self).quorum("isconflicting", q_type, id, msgHash): diff --git a/test/functional/feature_mnehf.py b/test/functional/feature_mnehf.py index 47e95df78f42..740ce21fa4ca 100755 --- a/test/functional/feature_mnehf.py +++ b/test/functional/feature_mnehf.py @@ -18,7 +18,6 @@ from test_framework.test_framework import ( DashTestFramework, - MasternodeInfo ) from test_framework.util import ( assert_equal, @@ -44,7 +43,7 @@ def restart_all_nodes(self, params=None): self.log.info(f"Actual restart options: {self.extra_args[inode]}") self.restart_node(0) - for mn in self.mninfo: # type: MasternodeInfo + for mn in self.mninfo: index = mn.nodeIdx self.stop_node(index) self.start_masternode(mn) diff --git a/test/functional/interface_zmq_dash.py b/test/functional/interface_zmq_dash.py index 212d6002ea1d..9fd7854aa636 100755 --- a/test/functional/interface_zmq_dash.py +++ b/test/functional/interface_zmq_dash.py @@ -14,7 +14,6 @@ from test_framework.test_framework import ( DashTestFramework, - MasternodeInfo, ) from test_framework.p2p import P2PInterface from test_framework.util import ( @@ -225,7 +224,7 @@ def validate_recovered_sig(request_id, msg_hash): sign_id = uint256_to_string(random.getrandbits(256)) sign_msg_hash = uint256_to_string(random.getrandbits(256)) quorumHash = self.nodes[0].quorum("selectquorum", 100, sign_id)["quorumHash"] - for mn in self.get_quorum_masternodes(quorumHash): # type: MasternodeInfo + for mn in self.get_quorum_masternodes(quorumHash): mn.get_node(self).quorum("sign", 100, sign_id, sign_msg_hash) validate_recovered_sig(sign_id, sign_msg_hash) # Unsubscribe from recovered signature messages diff --git a/test/functional/p2p_invalid_locator.py b/test/functional/p2p_invalid_locator.py index a586b48d4c00..2a521ec0d7a2 100755 --- a/test/functional/p2p_invalid_locator.py +++ b/test/functional/p2p_invalid_locator.py @@ -32,7 +32,7 @@ def run_test(self): within_max_peer = node.add_p2p_connection(P2PInterface()) msg.locator.vHave = [int(node.getblockhash(i - 1), 16) for i in range(block_count, block_count - (MAX_LOCATOR_SZ), -1)] within_max_peer.send_message(msg) - if type(msg) == msg_getheaders: + if type(msg) is msg_getheaders: within_max_peer.wait_for_header(node.getbestblockhash()) else: within_max_peer.wait_for_block(int(node.getbestblockhash(), 16)) diff --git a/test/functional/test_framework/crypto/siphash.py b/test/functional/test_framework/crypto/siphash.py index 884dbcab4694..bd13b2c948d8 100644 --- a/test/functional/test_framework/crypto/siphash.py +++ b/test/functional/test_framework/crypto/siphash.py @@ -31,7 +31,7 @@ def siphash_round(v0, v1, v2, v3): def siphash(k0, k1, data): - assert type(data) == bytes + assert type(data) is bytes v0 = 0x736f6d6570736575 ^ k0 v1 = 0x646f72616e646f6d ^ k1 v2 = 0x6c7967656e657261 ^ k0 @@ -61,5 +61,5 @@ def siphash(k0, k1, data): def siphash256(k0, k1, num): - assert type(num) == int + assert type(num) is int return siphash(k0, k1, num.to_bytes(32, 'little'))