dogecoin/test/functional/test_framework
fanquake cb1ee1551c
Merge #19674: refactor: test: use throwaway _ variable for unused loop counters
dac7a111bd 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 dac7a111bd
  instagibbs:
    manual inspection ACK dac7a111bd
  practicalswift:
    ACK dac7a111bd -- 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
2020-08-11 09:24:50 +08:00
..
__init__.py
address.py Revert "[TESTS] Move base58 to own module to break circular dependency" 2020-06-10 11:54:25 -04:00
authproxy.py test: retry when write to a socket fails on macOS 2020-06-25 17:26:20 +07:00
blocktools.py [test] CScriptNum Decode Check as Unit Tests 2020-06-03 07:18:01 -07:00
coverage.py
descriptors.py Output a descriptor in createmultisig and addmultisigaddress 2020-01-30 23:55:36 -05:00
key.py [tests] move generate_wif_key to wallet_util.py 2020-06-10 12:10:02 -04:00
messages.py refactor: test: use _ variable for unused loop counters 2020-08-06 18:39:33 +02:00
mininode.py test: Wait until is_connected in add_p2p_connection 2020-08-04 16:13:33 +02:00
netutil.py
script.py refactor: test: use _ variable for unused loop counters 2020-08-06 18:39:33 +02:00
script_util.py test: Remove unused, undocumented and misleading CScript.__add__ 2020-04-22 09:00:56 -04:00
segwit_addr.py
siphash.py
socks5.py
test_framework.py test: fix intermittent p2p_ibd_txrelay race, add test_framework.py#wait_until 2020-07-19 13:37:54 +02:00
test_node.py Merge #19657: test: Wait until is_connected in add_p2p_connection 2020-08-09 18:35:31 +02:00
test_shell.py TestShell: Return self from setup() 2019-11-05 12:55:52 +01:00
util.py refactor: test: use _ variable for unused loop counters 2020-08-06 18:39:33 +02:00
wallet_util.py [tests] move generate_wif_key to wallet_util.py 2020-06-10 12:10:02 -04:00