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).
test: use built-in collection types for type hints (Python 3.9 / PEP 585)
Since Python 3.9, type hinting has become a little less awkward, 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. [1] [2]
This commit applies the replacement for all Python scripts (i.e. in the
contrib and test folders) for the basic types:
- typing.Dict -> dict
- typing.List -> list
- typing.Set -> set
- typing.Tuple -> tuple
[1] https://docs.python.org/3.9/whatsnew/3.9.html#type-hinting-generics-in-standard-collections
[2] https://peps.python.org/pep-0585/#implementation for a list of type
d516cf83ed
scripted-diff: use PEP 585 built-in collection types for verify-binary script
-BEGIN VERIFY SCRIPT-
sed -i 's|t\.Dict|dict|g' ./contrib/verify-binaries/verify.py
sed -i 's|t\.List|list|g' ./contrib/verify-binaries/verify.py
sed -i 's|t\.Tuple|tuple|g' ./contrib/verify-binaries/verify.py
-END VERIFY SCRIPT-
4b9afb18e6
DrahtBot
commented at 11:42 PM on October 24, 2023:
contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
#27114 (p2p: Allow whitelisting outgoing connections by brunoerg)
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
DrahtBot added the label Tests on Oct 24, 2023
theStack renamed this: test: use built-in collection types for type hints (Python 3.9 / PEP 585) test: refactor: use built-in collection types for type hints (Python 3.9 / PEP 585) on Oct 24, 2023
DrahtBot added the label CI failed on Oct 25, 2023
DrahtBot removed the label CI failed on Oct 25, 2023
DrahtBot added the label CI failed on Oct 31, 2023
DrahtBot removed the label CI failed on Oct 31, 2023
kevkevinpal
commented at 11:03 PM on November 8, 2023:
contributor
running these two grep commands I got no results back which is good
grep -nr -e "Dict\[" -e "List\[" -e "Set\[" -e "Type\[" -e "Tuple\[" -e "FrozenSet\[" ./testgrep -nr -e "Dict\[" -e "List\[" -e "Set\[" -e "Type\[" -e "Tuple\[" -e "FrozenSet\[" ./contrib
and then running these and checking if there were anything we missed
grep -nri "from typing import" ./contribgrep -nri "from typing import" ./test
but only found ones that we couldn't use builtin collection types for
do we have a min supported python version for this project? Only concern is any one running below python 3.9 might not have these builtin collection type hints
Reducing boilerplate for type hints is nice, and even though there's no deprecation date set, from PEP585 it appears the intent is for the typing types is to be deprecated in favor of the generic types.
From PEP585, it's also recommended to replace Callable and Iterable with their collections.abc alternative, done is this diff:
<details>
<summary>git diff on 4b9afb18e6</summary>
Note: from python 3.10 onwards (PEP604), we can replace typing.Union[X, Y] with X | Y - and as a result, typing.Optional[X] with X | None
fanquake
commented at 10:24 AM on November 16, 2023:
member
Concept ACK
test: replace `Callable`/`Iterable` with their `collections.abc` alternative (PEP 585)a478c817b2
theStack
commented at 6:22 PM on November 16, 2023:
contributor
@stickies-v: Thanks, good idea, I've added your suggested diff as a commit. As far as I can see, the only remaining uses of the typing module in the PR branch are now Any, Optional, NoReturn and Union, for which no replacements exist.
stickies-v approved
stickies-v
commented at 7:08 PM on November 16, 2023:
contributor
ACKa478c817b2f62b7334b36e331a2e37fe8380c754
DrahtBot requested review from fanquake on Nov 16, 2023
fanquake approved
fanquake
commented at 10:36 AM on November 17, 2023:
member
ACKa478c817b2f62b7334b36e331a2e37fe8380c754
stickies-v
commented at 10:55 AM on November 17, 2023:
contributor
for which no replacements exist.
I think the NoReturn dependency is mostly because of suboptimal main() design, having main() return the exit code would be better imo (regardless of typing dependencies, but can be done later). That would only leave typing.Any (after python 3.10) for which it seems there is no alternative in sight.
<details>
<summary>git diff on a478c817b2</summary>
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2026-04-14 21:13 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me