Also include an unrelated variable rename:
Fix accidental redefinition via list comprehension
to be in par with core as it is part of the PR.
I removed W504 as it conflicts with autopep8, and W605 as it throws a lot of warnings. They will be
fixed and added in follow-ups to not bloat this diff.
Backport of core PR12295
https://github.com/bitcoin/bitcoin/pull/12295/files