From f86a3014338de6a2204bbdda10795b75ef6654c0 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 29 Jun 2023 15:41:27 -0600 Subject: [PATCH 1/5] script, test: add missing python type annotations Fix warnings for these files when ./test/lint/lint-python.py is run using mypy 0.991 (released 11/2022) and later: "By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]" For details, see: https://mypy-lang.blogspot.com/2022/11/mypy-0990-released.html --- contrib/devtools/test-security-check.py | 2 +- test/functional/p2p_message_capture.py | 2 +- test/functional/test_framework/test_framework.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/devtools/test-security-check.py b/contrib/devtools/test-security-check.py index 90268740c60..1390e310f28 100755 --- a/contrib/devtools/test-security-check.py +++ b/contrib/devtools/test-security-check.py @@ -28,7 +28,7 @@ def clean_files(source, executable): os.remove(source) os.remove(executable) -def call_security_check(cc, source, executable, options): +def call_security_check(cc: str, source: str, executable: str, options) -> tuple: # This should behave the same as AC_TRY_LINK, so arrange well-known flags # in the same order as autoconf would. # diff --git a/test/functional/p2p_message_capture.py b/test/functional/p2p_message_capture.py index 62ff4da8fd1..691a0b6409c 100755 --- a/test/functional/p2p_message_capture.py +++ b/test/functional/p2p_message_capture.py @@ -19,7 +19,7 @@ TIME_SIZE = 8 LENGTH_SIZE = 4 MSGTYPE_SIZE = 12 -def mini_parser(dat_file): +def mini_parser(dat_file: str) -> None: """Parse a data file created by CaptureMessageToFile. From the data file we'll only check the structure. diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index d3aae3fb9a2..73e7516ea7e 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -92,7 +92,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass): This class also contains various public and private helper methods.""" - def __init__(self): + def __init__(self) -> None: """Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method""" self.chain: str = 'regtest' self.setup_clean_chain: bool = False From 92408224a4cb2f454465d5ff8445c247f2c4318a Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 29 Jun 2023 15:18:49 -0600 Subject: [PATCH 2/5] test: fix PEP484 no implicit optional argument types errors Fix warnings for these files when ./test/lint/lint-python.py is run using mypy 0.991 (released 11/2022) and later: $ test/lint/lint-python.py test/functional/test_framework/coverage.py:23: error: Incompatible default for argument "coverage_logfile" (default has type "None", argument has type "str") [assignment] test/functional/test_framework/coverage.py:23: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True test/functional/test_framework/util.py:318: error: Incompatible default for argument "timeout" (default has type "None", argument has type "int") [assignment] test/functional/test_framework/util.py:318: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True test/functional/test_framework/util.py:318: error: Incompatible default for argument "coveragedir" (default has type "None", argument has type "str") [assignment] test/functional/interface_rest.py:67: error: Incompatible default for argument "query_params" (default has type "None", argument has type "dict[str, Any]") [assignment] test/functional/interface_rest.py:67: note: PEP 484 prohibits implicit Optional. Accordingly, mypy has changed its default to no_implicit_optional=True Verified using https://github.com/hauntsaninja/no_implicit_optional For details, see: https://mypy-lang.blogspot.com/2022/11/mypy-0990-released.html --- test/functional/interface_rest.py | 3 ++- test/functional/test_framework/coverage.py | 3 ++- test/functional/test_framework/util.py | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index 1ba8f60d99c..c0679c5ba9c 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -26,6 +26,7 @@ from test_framework.wallet import ( MiniWallet, getnewdestination, ) +from typing import Optional INVALID_PARAM = "abc" @@ -64,7 +65,7 @@ class RESTTest (BitcoinTestFramework): body: str = '', status: int = 200, ret_type: RetType = RetType.JSON, - query_params: typing.Dict[str, typing.Any] = None, + query_params: Optional[typing.Dict[str, typing.Any]] = None, ) -> typing.Union[http.client.HTTPResponse, bytes, str, None]: rest_uri = '/rest' + uri if req_type in ReqType: diff --git a/test/functional/test_framework/coverage.py b/test/functional/test_framework/coverage.py index 4fb4f8bb821..912a945d958 100644 --- a/test/functional/test_framework/coverage.py +++ b/test/functional/test_framework/coverage.py @@ -11,6 +11,7 @@ testing. import os from .authproxy import AuthServiceProxy +from typing import Optional REFERENCE_FILENAME = 'rpc_interface.txt' @@ -20,7 +21,7 @@ class AuthServiceProxyWrapper(): An object that wraps AuthServiceProxy to record specific RPC calls. """ - def __init__(self, auth_service_proxy_instance: AuthServiceProxy, rpc_url: str, coverage_logfile: str=None): + def __init__(self, auth_service_proxy_instance: AuthServiceProxy, rpc_url: str, coverage_logfile: Optional[str]=None): """ Kwargs: auth_service_proxy_instance: the instance being wrapped. diff --git a/test/functional/test_framework/util.py b/test/functional/test_framework/util.py index e480d63e03a..9143397042f 100644 --- a/test/functional/test_framework/util.py +++ b/test/functional/test_framework/util.py @@ -309,7 +309,7 @@ class PortSeed: n = None -def get_rpc_proxy(url: str, node_number: int, *, timeout: int=None, coveragedir: str=None) -> coverage.AuthServiceProxyWrapper: +def get_rpc_proxy(url: str, node_number: int, *, timeout: Optional[int]=None, coveragedir: Optional[str]=None) -> coverage.AuthServiceProxyWrapper: """ Args: url: URL of the RPC server to call From 146c861da2e4236997bee3eed6110a5016a8b86b Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 15 Jun 2023 15:08:43 -0600 Subject: [PATCH 3/5] script: update linter dependencies --- ci/lint/04_install.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ci/lint/04_install.sh b/ci/lint/04_install.sh index 737cf3e2fbf..b3b1c91ee01 100755 --- a/ci/lint/04_install.sh +++ b/ci/lint/04_install.sh @@ -33,11 +33,11 @@ if [ -z "${SKIP_PYTHON_INSTALL}" ]; then python3 --version fi -${CI_RETRY_EXE} pip3 install codespell==2.2.1 -${CI_RETRY_EXE} pip3 install flake8==5.0.4 -${CI_RETRY_EXE} pip3 install lief==0.13.1 -${CI_RETRY_EXE} pip3 install mypy==0.971 -${CI_RETRY_EXE} pip3 install pyzmq==24.0.1 +${CI_RETRY_EXE} pip3 install codespell==2.2.5 +${CI_RETRY_EXE} pip3 install flake8==6.0.0 +${CI_RETRY_EXE} pip3 install lief==0.13.2 +${CI_RETRY_EXE} pip3 install mypy==1.4.1 +${CI_RETRY_EXE} pip3 install pyzmq==25.1.0 ${CI_RETRY_EXE} pip3 install vulture==2.6 SHELLCHECK_VERSION=v0.8.0 From 1316119ce7ba3de4135bbf1e5ac28c9ea26f62e1 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 15 Jun 2023 15:07:15 -0600 Subject: [PATCH 4/5] script: update ignored-words.txt --- test/lint/spelling.ignore-words.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/lint/spelling.ignore-words.txt b/test/lint/spelling.ignore-words.txt index fa47a317252..ecc2a553d20 100644 --- a/test/lint/spelling.ignore-words.txt +++ b/test/lint/spelling.ignore-words.txt @@ -1,3 +1,4 @@ +afile asend ba blockin @@ -15,6 +16,7 @@ lief mor nd nin +requestor ser siz stap From 6c97757a480b6e71a0750330d69ff18ac7cc6127 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Thu, 15 Jun 2023 15:08:03 -0600 Subject: [PATCH 5/5] script: appease spelling linter --- src/addrdb.cpp | 2 +- src/test/miniminer_tests.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/addrdb.cpp b/src/addrdb.cpp index cb1c49050ef..0fcb5ed5c97 100644 --- a/src/addrdb.cpp +++ b/src/addrdb.cpp @@ -210,7 +210,7 @@ util::Result> LoadAddrman(const NetGroupManager& netgro return util::Error{strprintf(_("Invalid or corrupt peers.dat (%s). If you believe this is a bug, please report it to %s. As a workaround, you can move the file (%s) out of the way (rename, move, or delete) to have a new one created on the next start."), e.what(), PACKAGE_BUGREPORT, fs::quoted(fs::PathToString(path_addr)))}; } - return {std::move(addrman)}; // std::move should be unneccessary but is temporarily needed to work around clang bug + return {std::move(addrman)}; // std::move should be unnecessary but is temporarily needed to work around clang bug // (https://github.com/bitcoin/bitcoin/pull/25977#issuecomment-1561270092) } diff --git a/src/test/miniminer_tests.cpp b/src/test/miniminer_tests.cpp index b26f7dafe34..1ee9e0c0664 100644 --- a/src/test/miniminer_tests.cpp +++ b/src/test/miniminer_tests.cpp @@ -463,8 +463,8 @@ BOOST_FIXTURE_TEST_CASE(calculate_cluster, TestChain100Setup) } const auto vec_iters_zigzag = pool.GetIterVec(zigzag_txids); // It doesn't matter which tx we calculate cluster for, everybody is in it. - const std::vector indeces{0, 22, 72, zigzag_txids.size() - 1}; - for (const auto index : indeces) { + const std::vector indices{0, 22, 72, zigzag_txids.size() - 1}; + for (const auto index : indices) { const auto cluster = pool.GatherClusters({zigzag_txids[index]}); BOOST_CHECK_EQUAL(cluster.size(), zigzag_txids.size()); CTxMemPool::setEntries clusterset{cluster.begin(), cluster.end()};