Page MenuHomePhabricator

refactor: test: use _ variable for unused loop counters
ClosedPublic

Authored by PiRK on Sep 7 2021, 15:16.

Details

Reviewers
majcosta
Group Reviewers
Restricted Project
Commits
rABC7b81a4a8aac4: refactor: test: use _ variable for unused loop counters
Summary

substitutes "for x in range(N):" by "for _ in range(N):"
indicates to the reader that a block is just repeated N times, and
that the loop counter is not used in the body

Backport notes:

  • this PR also replaces a few occurences of range(0, x) with range(x)
  • test/functional/p2p_tx_download.py has been included in test/functional/p2p_inv_download.py, and was already up to date

This is a backport of core#19674

Test Plan

ninja check-functional-extended

Diff Detail

Event Timeline

PiRK requested review of this revision.Sep 7 2021, 15:16

Additional note: I had a quick look to see if there is an automated linter solution (autopep8...) for this. I couldn't find any.

Using _ as a throwaway variable is an often used idiom in python, but it is not universally considered a good practice. It can conflict with _ used as an internationalization function name. An alternative would be _i.

This revision is now accepted and ready to land.Sep 7 2021, 15:56