Skip to content

Commit 260b1d7

Browse files
committed
Merge bitcoin/bitcoin#22092: test: convert documentation into type annotations
68ace23 test: convert docs into type annotations in test_framework/test_node.py (fanquake) 8bfcba3 test: convert docs into type annotations in test_framework/wallet.py (fanquake) b043ca8 test: convert docs into type annotations in test_framework/util.py (fanquake) Pull request description: Rather than having function types exist as documentation, make them type annotations, which enables more `mypy` checking. ACKs for top commit: instagibbs: utACK bitcoin/bitcoin@68ace23 Tree-SHA512: b705f26b48baabde07b9b2c0a8d547b4dcca291b16eaf5ac70462bb3a1f9e9c2783d93a9d4290889d0cbb3f7db3671446754411a1f498b265d336f6ff33478df
2 parents 1cc123f + 68ace23 commit 260b1d7

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

test/functional/test_framework/test_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,14 @@ def assert_debug_log(self, expected_msgs, unexpected_msgs=None, timeout=2):
400400
self._raise_assertion_error('Expected messages "{}" does not partially match log:\n\n{}\n\n'.format(str(expected_msgs), print_log))
401401

402402
@contextlib.contextmanager
403-
def profile_with_perf(self, profile_name):
403+
def profile_with_perf(self, profile_name: str):
404404
"""
405405
Context manager that allows easy profiling of node activity using `perf`.
406406
407407
See `test/functional/README.md` for details on perf usage.
408408
409409
Args:
410-
profile_name (str): This string will be appended to the
410+
profile_name: This string will be appended to the
411411
profile data filename generated by perf.
412412
"""
413413
subp = self._start_perf(profile_name)

test/functional/test_framework/util.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from . import coverage
2121
from .authproxy import AuthServiceProxy, JSONRPCException
2222
from io import BytesIO
23+
from typing import Callable, Optional
2324

2425
logger = logging.getLogger("TestFramework.utils")
2526

@@ -80,17 +81,17 @@ def assert_raises_message(exc, message, fun, *args, **kwds):
8081
raise AssertionError("No exception raised")
8182

8283

83-
def assert_raises_process_error(returncode, output, fun, *args, **kwds):
84+
def assert_raises_process_error(returncode: int, output: str, fun: Callable, *args, **kwds):
8485
"""Execute a process and asserts the process return code and output.
8586
8687
Calls function `fun` with arguments `args` and `kwds`. Catches a CalledProcessError
8788
and verifies that the return code and output are as expected. Throws AssertionError if
8889
no CalledProcessError was raised or if the return code and output are not as expected.
8990
9091
Args:
91-
returncode (int): the process return code.
92-
output (string): [a substring of] the process output.
93-
fun (function): the function to call. This should execute a process.
92+
returncode: the process return code.
93+
output: [a substring of] the process output.
94+
fun: the function to call. This should execute a process.
9495
args*: positional arguments for the function.
9596
kwds**: named arguments for the function.
9697
"""
@@ -105,19 +106,19 @@ def assert_raises_process_error(returncode, output, fun, *args, **kwds):
105106
raise AssertionError("No exception raised")
106107

107108

108-
def assert_raises_rpc_error(code, message, fun, *args, **kwds):
109+
def assert_raises_rpc_error(code: Optional[int], message: Optional[str], fun: Callable, *args, **kwds):
109110
"""Run an RPC and verify that a specific JSONRPC exception code and message is raised.
110111
111112
Calls function `fun` with arguments `args` and `kwds`. Catches a JSONRPCException
112113
and verifies that the error code and message are as expected. Throws AssertionError if
113114
no JSONRPCException was raised or if the error code/message are not as expected.
114115
115116
Args:
116-
code (int), optional: the error code returned by the RPC call (defined
117-
in src/rpc/protocol.h). Set to None if checking the error code is not required.
118-
message (string), optional: [a substring of] the error string returned by the
119-
RPC call. Set to None if checking the error string is not required.
120-
fun (function): the function to call. This should be the name of an RPC.
117+
code: the error code returned by the RPC call (defined in src/rpc/protocol.h).
118+
Set to None if checking the error code is not required.
119+
message: [a substring of] the error string returned by the RPC call.
120+
Set to None if checking the error string is not required.
121+
fun: the function to call. This should be the name of an RPC.
121122
args*: positional arguments for the function.
122123
kwds**: named arguments for the function.
123124
"""

test/functional/test_framework/wallet.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
from decimal import Decimal
88
from enum import Enum
9+
from typing import Optional
910
from test_framework.address import ADDRESS_BCRT1_P2WSH_OP_TRUE
1011
from test_framework.key import ECKey
1112
from test_framework.messages import (
@@ -105,12 +106,12 @@ def generate(self, num_blocks):
105106
def get_address(self):
106107
return self._address
107108

108-
def get_utxo(self, *, txid='', mark_as_spent=True):
109+
def get_utxo(self, *, txid: Optional[str]='', mark_as_spent=True):
109110
"""
110111
Returns a utxo and marks it as spent (pops it from the internal list)
111112
112113
Args:
113-
txid (string), optional: get the first utxo we find from a specific transaction
114+
txid: get the first utxo we find from a specific transaction
114115
115116
Note: Can be used to get the change output immediately after a send_self_transfer
116117
"""

0 commit comments

Comments
 (0)