mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-26 05:48:20 +01:00
Merge bitcoin/bitcoin#28725: test: refactor: use built-in collection types for type hints (Python 3.9 / PEP 585)
a478c817b2test: replace `Callable`/`Iterable` with their `collections.abc` alternative (PEP 585) (stickies-v)4b9afb18e6scripted-diff: use PEP 585 built-in collection types for verify-binary script (Sebastian Falbesoner)d516cf83edtest: 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: ACKa478c817b2fanquake: ACKa478c817b2Tree-SHA512: 6948c905f6abd644d84f09fcb3661d7edb2742e8f2b28560008697d251d77a61a1146ab4b070e65b0d27acede7a5256703da7bf6eb1c7c3a897755478c76c6e8
This commit is contained in:
@@ -10,7 +10,6 @@ This file is modified from python-bitcoinlib.
|
||||
from collections import namedtuple
|
||||
import struct
|
||||
import unittest
|
||||
from typing import List, Dict
|
||||
|
||||
from .key import TaggedHash, tweak_add_pubkey, compute_xonly_pubkey
|
||||
|
||||
@@ -110,8 +109,8 @@ class CScriptOp(int):
|
||||
_opcode_instances.append(super().__new__(cls, n))
|
||||
return _opcode_instances[n]
|
||||
|
||||
OPCODE_NAMES: Dict[CScriptOp, str] = {}
|
||||
_opcode_instances: List[CScriptOp] = []
|
||||
OPCODE_NAMES: dict[CScriptOp, str] = {}
|
||||
_opcode_instances: list[CScriptOp] = []
|
||||
|
||||
# Populate opcode instance table
|
||||
for n in range(0xff + 1):
|
||||
|
||||
Reference in New Issue
Block a user