Skip to content

Commit 4c55f92

Browse files
author
MarcoFalke
committed
Merge #20954: test: Declare nodes type in test_framework.py.
5353b0c Change type definitions for "chain" and "setup_clean_chain" from type comments to Python 3.6+ types. Additionally, set type for "nodes". (Kiminuo) Pull request description: ### Motivation When I wanted to understand better https://github.com/bitcoin/bitcoin/pull/19145/files#diff-4bebbd3b112dc222ea7e75ef051838ceffcee63b9e9234a98a4cc7251d34451b test, I noticed that navigation in PyCharm/VS Code did not work for `nodes` variable. I think this is frustrating, especially for newcomers. ### Summary * This PR modifies Python 3.5 [type comments](https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#variables) to Python 3.6+ types and adds a proper type for `nodes` [instance attribute](https://mypy.readthedocs.io/en/stable/class_basics.html#instance-and-class-attributes). * This PR does not change behavior. * This PR is intentionally very small, if the concept is accepted, a follow-up PRs can be more ambitious. ### End result 1. Open `test/functional/feature_abortnode.py` 2. Move your caret to: `self.nodes[0].generate[caret here](3)` 3. Use "Go to definition" [F12] should work now. I have tested this on PyCharm (Windows, Ubuntu) and VS Code (Windows, Ubuntu). Note: Some `TestNode` methods (e.g. `self.nodes[0].getblock(...)` ) use `__call__` mechanism and navigation does not work for them even with this PR. ACKs for top commit: laanwj: ACK 5353b0c theStack: ACK 5353b0c Tree-SHA512: 821773f052ab9b2889dc357d38c59407a4af09e3b86d7134fcca7d78e5edf3a5ede9bfb37595ea97caf9ebfcbda372bcf73763b7f89b0677670f21b3e396a12b
2 parents 1f51433 + 5353b0c commit 4c55f92

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

test/functional/test_framework/test_framework.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import tempfile
1919
import time
2020

21+
from typing import List
2122
from .authproxy import JSONRPCException
2223
from . import coverage
2324
from .p2p import NetworkThread
@@ -89,14 +90,11 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
8990
9091
This class also contains various public and private helper methods."""
9192

92-
chain = None # type: str
93-
setup_clean_chain = None # type: bool
94-
9593
def __init__(self):
9694
"""Sets test framework defaults. Do not override this method. Instead, override the set_test_params() method"""
97-
self.chain = 'regtest'
98-
self.setup_clean_chain = False
99-
self.nodes = []
95+
self.chain: str = 'regtest'
96+
self.setup_clean_chain: bool = False
97+
self.nodes: List[TestNode] = []
10098
self.network_thread = None
10199
self.rpc_timeout = 60 # Wait for up to 60 seconds for the RPC server to respond
102100
self.supports_cli = True

0 commit comments

Comments
 (0)