mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
9d33b30a87
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
|
||
---|---|---|
.. | ||
__init__.py | ||
address.py | ||
authproxy.py | ||
blocktools.py | ||
coverage.py | ||
descriptors.py | ||
key.py | ||
messages.py | ||
mininode.py | ||
muhash.py | ||
netutil.py | ||
ripemd160.py | ||
script_util.py | ||
script.py | ||
siphash.py | ||
socks5.py | ||
test_framework.py | ||
test_node.py | ||
test_shell.py | ||
util.py | ||
wallet_util.py |