diff options
author | fanquake <fanquake@gmail.com> | 2021-11-11 20:07:57 +0800 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2021-11-11 20:33:02 +0800 |
commit | d217ee25a3979b32c320052d079bac342c7ee976 (patch) | |
tree | b45a65bbd8eeda686840233eb53d58dd9cff38f0 /build_msvc/libbitcoin_wallet | |
parent | f63bf05e73ea96e5c2c72cc455d05ad382883c27 (diff) | |
parent | 467fe5779ca85bd8d58fde65948ffc8c35078e60 (diff) | |
download | bitcoin-d217ee25a3979b32c320052d079bac342c7ee976.tar.xz |
Merge bitcoin/bitcoin#23420: test: Correct MyPy typing for subtest decorator
467fe5779ca85bd8d58fde65948ffc8c35078e60 test: Correct MyPy typing for subtest decorator (Pavel Safronov)
Pull request description:
This is the part of the effort to make python typing correct https://github.com/bitcoin/bitcoin/issues/19389
The typing of the `subtest` decorator within `p2p_segwit.py` test file was incorrect.
Since `subtest` function is defined as a member of the class, it expects `self` as a first argument, and it is not provided. Hence the typing errors (that are currently suppressed by `type: ignore`).
```
(venv) vagrant@ubuntu-focal:/vagrant/test/functional$ mypy p2p_segwit.py
p2p_segwit.py:298: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:327: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:358: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:447: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:519: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:561: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:659: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:670: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:737: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:826: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:866: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:941: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:977: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1052: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1089: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1136: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1220: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1312: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1406: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1440: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1543: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1729: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1782: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1881: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:1983: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
p2p_segwit.py:2027: error: Argument 1 to "subtest" has incompatible type "Callable[[SegWitTest], Any]"; expected "SegWitTest"
Found 26 errors in 1 file (checked 1 source file)
```
However, the tests are passing, because there is no `self` argument passed when it is called as a decorator.
There is also suppressed pylint error `# noqa: N805` pointing to the same issue.
```
N805 first argument of a method should be named 'self'
```
So the solution is to move the `subtest` definition outside the class, so the `self` argument is no longer required.
After doing so, both mypy and unittests are successfully passing:
```
(venv) vagrant@ubuntu-focal:/vagrant/test/functional$ mypy p2p_segwit.py
Success: no issues found in 1 source file
```
```
(venv) vagrant@ubuntu-focal:/vagrant/test/functional$ ./test_runner.py p2p_segwit
Temporary test directory at /tmp/test_runner__🏃_20211103_011449
Running Unit Tests for Test Framework Modules
..........
----------------------------------------------------------------------
Ran 10 tests in 0.546s
OK
Remaining jobs: [p2p_segwit.py]
1/1 - p2p_segwit.py passed, Duration: 81 s
TEST | STATUS | DURATION
p2p_segwit.py | ✓ Passed | 81 s
ALL | ✓ Passed | 81 s (accumulated)
Runtime: 81 s
```
```
ACKs for top commit:
fanquake:
ACK 467fe5779ca85bd8d58fde65948ffc8c35078e60
Tree-SHA512: e4c3e2d284f47a6bfbf4af22d4021123cdd9c2ea16ec90a91b466ad1a5af615bb4e15959e6cf56c788701d7e7cbda91a8ffc4347965095c3384eae3d28f261af
Diffstat (limited to 'build_msvc/libbitcoin_wallet')
0 files changed, 0 insertions, 0 deletions