mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 22:50:59 +01:00
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
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):
|
||||
|
||||
@@ -19,7 +19,6 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
from typing import List
|
||||
from .address import create_deterministic_address_bcrt1_p2tr_op_true
|
||||
from .authproxy import JSONRPCException
|
||||
from . import coverage
|
||||
@@ -96,7 +95,7 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
"""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
|
||||
self.nodes: List[TestNode] = []
|
||||
self.nodes: list[TestNode] = []
|
||||
self.extra_args = None
|
||||
self.network_thread = None
|
||||
self.rpc_timeout = 60 # Wait for up to 60 seconds for the RPC server to respond
|
||||
|
||||
@@ -20,7 +20,7 @@ import time
|
||||
|
||||
from . import coverage
|
||||
from .authproxy import AuthServiceProxy, JSONRPCException
|
||||
from typing import Callable, Optional, Tuple
|
||||
from typing import Callable, Optional
|
||||
|
||||
logger = logging.getLogger("TestFramework.utils")
|
||||
|
||||
@@ -416,7 +416,7 @@ def get_datadir_path(dirname, n):
|
||||
return pathlib.Path(dirname) / f"node{n}"
|
||||
|
||||
|
||||
def get_temp_default_datadir(temp_dir: pathlib.Path) -> Tuple[dict, pathlib.Path]:
|
||||
def get_temp_default_datadir(temp_dir: pathlib.Path) -> tuple[dict, pathlib.Path]:
|
||||
"""Return os-specific environment variables that can be set to make the
|
||||
GetDefaultDataDir() function return a datadir path under the provided
|
||||
temp_dir, as well as the complete path it would return."""
|
||||
|
||||
@@ -9,7 +9,6 @@ from decimal import Decimal
|
||||
from enum import Enum
|
||||
from typing import (
|
||||
Any,
|
||||
List,
|
||||
Optional,
|
||||
)
|
||||
from test_framework.address import (
|
||||
@@ -284,7 +283,7 @@ class MiniWallet:
|
||||
def create_self_transfer_multi(
|
||||
self,
|
||||
*,
|
||||
utxos_to_spend: Optional[List[dict]] = None,
|
||||
utxos_to_spend: Optional[list[dict]] = None,
|
||||
num_outputs=1,
|
||||
amount_per_output=0,
|
||||
locktime=0,
|
||||
|
||||
Reference in New Issue
Block a user