aboutsummaryrefslogtreecommitdiff
path: root/test/lint
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-11-17 11:03:15 +0000
committerfanquake <fanquake@gmail.com>2023-11-17 11:19:17 +0000
commit98b0acda0f00df3f62a61646d323c8367ddebd68 (patch)
treea79bc8c8d5009bbc27b7ee0918da2bcb68df7a3a /test/lint
parent950af7c8767aaaf66fe329cb10deaf0aea8e6ed9 (diff)
parenta478c817b2f62b7334b36e331a2e37fe8380c754 (diff)
downloadbitcoin-98b0acda0f00df3f62a61646d323c8367ddebd68.tar.xz
Merge bitcoin/bitcoin#28725: test: refactor: use built-in collection types for type hints (Python 3.9 / PEP 585)
a478c817b2f62b7334b36e331a2e37fe8380c754 test: replace `Callable`/`Iterable` with their `collections.abc` alternative (PEP 585) (stickies-v) 4b9afb18e6b9e16d7b299820f3a1382986a451d4 scripted-diff: use PEP 585 built-in collection types for verify-binary script (Sebastian Falbesoner) d516cf83ed2da86dfefb395cd46f8a894907b88e test: use built-in collection types for type hints (Python 3.9 / PEP 585) (Sebastian Falbesoner) Pull request description: With Python 3.9 / [PEP 585](https://peps.python.org/pep-0585/), [type hinting has become a little less awkward](https://docs.python.org/3.9/whatsnew/3.9.html#type-hinting-generics-in-standard-collections), as for collection types one doesn't need to import the corresponding capitalized types (`Dict`, `List`, `Set`, `Tuple`, ...) anymore, but can use the built-in types directly (see https://peps.python.org/pep-0585/#implementation for the full list). This PR applies the replacement for all Python scripts (i.e. in the contrib and test folders) for the basic types, i.e.: - typing.Dict -> dict - typing.List -> list - typing.Set -> set - typing.Tuple -> tuple For an additional check, I ran mypy 1.6.1 on both master and the PR branch via ``` $ mypy --ignore-missing-imports --explicit-package-bases $(git ls-files "*.py") ``` and verified that the output is identical -- (from the 22 identified problems, most look like false-positives, it's probably worth it to go deeper here and address them in a follow-up though). ACKs for top commit: stickies-v: ACK a478c817b2f62b7334b36e331a2e37fe8380c754 fanquake: ACK a478c817b2f62b7334b36e331a2e37fe8380c754 Tree-SHA512: 6948c905f6abd644d84f09fcb3661d7edb2742e8f2b28560008697d251d77a61a1146ab4b070e65b0d27acede7a5256703da7bf6eb1c7c3a897755478c76c6e8
Diffstat (limited to 'test/lint')
-rwxr-xr-xtest/lint/lint-files.py4
-rwxr-xr-xtest/lint/lint-include-guards.py3
2 files changed, 3 insertions, 4 deletions
diff --git a/test/lint/lint-files.py b/test/lint/lint-files.py
index f2b5db681b..86fe727b06 100755
--- a/test/lint/lint-files.py
+++ b/test/lint/lint-files.py
@@ -11,7 +11,7 @@ import os
import re
import sys
from subprocess import check_output
-from typing import Dict, Optional, NoReturn
+from typing import Optional, NoReturn
CMD_TOP_LEVEL = ["git", "rev-parse", "--show-toplevel"]
CMD_ALL_FILES = ["git", "ls-files", "-z", "--full-name", "--stage"]
@@ -69,7 +69,7 @@ class FileMeta(object):
return None
-def get_git_file_metadata() -> Dict[str, FileMeta]:
+def get_git_file_metadata() -> dict[str, FileMeta]:
'''
Return a dictionary mapping the name of all files in the repository to git tree metadata.
'''
diff --git a/test/lint/lint-include-guards.py b/test/lint/lint-include-guards.py
index 48b918e9da..291e528c1d 100755
--- a/test/lint/lint-include-guards.py
+++ b/test/lint/lint-include-guards.py
@@ -11,7 +11,6 @@ Check include guards.
import re
import sys
from subprocess import check_output
-from typing import List
HEADER_ID_PREFIX = 'BITCOIN_'
@@ -28,7 +27,7 @@ EXCLUDE_FILES_WITH_PREFIX = ['contrib/devtools/bitcoin-tidy',
'src/test/fuzz/FuzzedDataProvider.h']
-def _get_header_file_lst() -> List[str]:
+def _get_header_file_lst() -> list[str]:
""" Helper function to get a list of header filepaths to be
checked for include guards.
"""