You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR adds initial support for type hints checking in python scripts.
Support for type hints was introduced in Python 3.5. Type hints make it easier to read and review code in my opinion. Also an IDE may discover a potential bug sooner. Yet, as PEP 484 says: "It should also be emphasized that Python will remain a dynamically typed language, and the authors have no desire to ever make type hints mandatory, even by convention."
Mypy is used in lint-python.sh to do the type checking. The package is standard so there is little chance that it will be abandoned. Mypy checks that type hints in source code are correct when they are not, it fails with an error.
Useful resources:
* https://docs.python.org/3.5/library/typing.html
* https://www.python.org/dev/peps/pep-0484/
Copy file name to clipboardExpand all lines: test/functional/README.md
+4-2Lines changed: 4 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,12 @@ don't have test cases for.
26
26
The Travis linter also checks this, but [possibly not in all cases](https://github.com/bitcoin/bitcoin/pull/14884#discussion_r239585126).
27
27
- See [the python lint script](/test/lint/lint-python.sh) that checks for violations that
28
28
could lead to bugs and issues in the test code.
29
+
- Use [type hints](https://docs.python.org/3/library/typing.html) in your code to improve code readability
30
+
and to detect possible bugs earlier.
29
31
- Avoid wildcard imports
30
32
- Use a module-level docstring to describe what the test is testing, and how it
31
33
is testing it.
32
-
- When subclassing the BitcoinTestFramwork, place overrides for the
34
+
- When subclassing the BitcoinTestFramework, place overrides for the
33
35
`set_test_params()`, `add_options()` and `setup_xxxx()` methods at the top of
34
36
the subclass, then locally-defined helper methods, then the `run_test()` method.
35
37
- Use `'{}'.format(x)` for string formatting, not `'%s' % x`.
@@ -45,7 +47,7 @@ don't have test cases for.
45
47
-`rpc` for tests for individual RPC methods or features, eg `rpc_listtransactions.py`
46
48
-`tool` for tests for tools, eg `tool_wallet.py`
47
49
-`wallet` for tests for wallet features, eg `wallet_keypool.py`
48
-
-use an underscore to separate words
50
+
-Use an underscore to separate words
49
51
- exception: for tests for specific RPCs or command line options which don't include underscores, name the test after the exact RPC or argument name, eg `rpc_decodescript.py`, not `rpc_decode_script.py`
50
52
- Don't use the redundant word `test` in the name, eg `interface_zmq.py`, not `interface_zmq_test.py`
0 commit comments