dash/test/functional/test_framework
fanquake 9d33b30a87
Merge #19674: refactor: test: use throwaway _ variable for unused loop counters
dac7a111bdd3b0233d94cf68dae7a8bfc6ac9c64 refactor: test: use _ variable for unused loop counters (Sebastian Falbesoner)

Pull request description:

  This tiny PR substitutes Python loops in the form of `for x in range(N): ...` by `for _ in range(N): ...` where applicable. The idea is indicating to the reader that a block (or statement, in list comprehensions) is just repeated N times, and that the loop counter is not used in the body, hence using the throwaway variable. This is already done quite often in the current tests (see e.g. `$ git grep "for _ in range("`). Another alternative would be using `itertools.repeat` (according to Python core developer Raymond Hettinger it's [even faster](https://twitter.com/raymondh/status/1144527183341375488)), but that doesn't seem to be widespread in use and I'm not sure about a readability increase.

  The only drawback I see is that whenever one wants to debug loop iterations, one would need to introduce a loop variable again. Reviewing this is basically a no-brainer, since tests would fail immediately if a a substitution has taken place on a loop where the variable is used.

  Instances to replace were found by `$ git grep "for.*in range("` and manually checked.

ACKs for top commit:
  darosior:
    ACK dac7a111bdd3b0233d94cf68dae7a8bfc6ac9c64
  instagibbs:
    manual inspection ACK dac7a111bd
  practicalswift:
    ACK dac7a111bdd3b0233d94cf68dae7a8bfc6ac9c64 -- the updated code is easier to reason about since the throwaway nature of a variable is expressed explicitly (using the Pythonic `_` idiom) instead of implicitly. Explicit is better than implicit was we all know by now :)

Tree-SHA512: 5f43ded9ce14e5e00b3876ec445b90acda1842f813149ae7bafa93f3ac3d510bb778e2c701187fd2c73585e6b87797bb2d2987139bd1a9ba7d58775a59392406
2024-01-20 00:07:09 +07:00
..
__init__.py
address.py Merge #18965: tests: implement base58_decode 2023-12-06 12:33:15 -06:00
authproxy.py Merge #19368: test: improve functional tests compatibility with BSD/macOS 2024-01-06 19:30:15 -06:00
blocktools.py fix: some fixes for block payee validation and corresponding tests (#5684) 2023-11-13 10:02:52 -06:00
coverage.py Merge bitcoin/bitcoin#22139: test: add type annotations to util.get_rpc_proxy 2023-12-03 20:13:09 -06:00
descriptors.py Merge #18032: rpc: Output a descriptor in createmultisig and addmultisigaddress 2023-04-06 20:15:47 +03:00
key.py merge bitcoin#19105: Add Muhash3072 implementation in Python 2022-04-27 20:05:13 +05:30
messages.py Merge #19674: refactor: test: use throwaway _ variable for unused loop counters 2024-01-20 00:07:09 +07:00
mininode.py Merge bitcoin/bitcoin#25126: test: add BIP157 message parsing support (via MESSAGEMAP) 2024-01-14 11:05:37 -06:00
muhash.py partial bitcoin#19055: Add MuHash3072 implementation 2022-04-27 20:05:13 +05:30
netutil.py
ripemd160.py docs/build: Kubuntu 22.04 build fix (#4843) 2022-05-28 23:27:04 -05:00
script_util.py Merge #18732: test: Remove unused, undocumented and misleading CScript.__add__ 2023-03-03 23:07:15 +05:30
script.py Merge #19674: refactor: test: use throwaway _ variable for unused loop counters 2024-01-20 00:07:09 +07:00
siphash.py
socks5.py
test_framework.py Merge #18210: test: type hints in Python tests 2024-01-10 12:07:54 -06:00
test_node.py Merge bitcoin/bitcoin#22139: test: add type annotations to util.get_rpc_proxy 2023-12-03 20:13:09 -06:00
test_shell.py Merge #17378: TestShell: Fix typos & implement cleanups 2023-01-23 12:22:29 -06:00
util.py Merge #19674: refactor: test: use throwaway _ variable for unused loop counters 2024-01-20 00:07:09 +07:00
wallet_util.py Merge #17891: scripted-diff: Replace CCriticalSection with RecursiveMutex 2023-05-24 12:43:57 -05:00