Skip to content

Conversation

willcl-ark
Copy link
Member

Fix E275 errors in lint-python.py with flake8 5.0.4

After updating my venv to Python 3.6.15 and reinstalling flake8 (at the current version, 5.0.4), it now throws quite a few E275 which are fixed with this scripted diff.

@fanquake
Copy link
Member

fanquake commented Nov 8, 2022

Duplicate of #26257.

@maflcko
Copy link
Member

maflcko commented Nov 8, 2022

Not sure. To me it seems odd to enforce this whitespace but no other. If you want to enforce whitespace, it might be best to discuss for all whitespace, unless there is a reason to do it for only this one.

@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 8, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26359 (p2p, refactor: p2p: Erlay support signaling #23443 (Erlay support signaling) follow-ups by naumenkogs)
  • #26356 (test: Use consistent assert functions by NorrinRadd)
  • #26325 (rpc: Return accurate results for scanblocks by aureleoules)
  • #26257 (script, test: python linter fixups and updates by jonatack)
  • #26222 (Introduce field element and group element classes to test_framework/key.py by sipa)
  • #25766 (wallet: Include a signature with encrypted keys to mitigate a wallet scam by achow101)
  • #24005 (test: add python implementation of Elligator swift by stratospher)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@willcl-ark
Copy link
Member Author

First, sorry I missed duplicating #26257 (but I also think a scripted diff is the best way to make this change).

@MarcoFalke which other whitespace did you have in mind?

IMO if we are using a specific linter then we should try to ensure those lints pass (or are disabled) and not more without adding additional lints for it. Otherwise if we change "all" whitespace today, we are likely to miss more of the same un-linted whitespace errors being introduced in the future.

@maflcko
Copy link
Member

maflcko commented Nov 8, 2022

scripted diff is the best way

The scripted diff as of now may modify out-of-git-tree files with the wildcard. You'd have to use git to get the file list. Also, it doesn't pass CI as of now.

@MarcoFalke which other whitespace did you have in mind?

Anything you could come up with. Pretty sure there are other whitespace/formatting checks in flake. If not, you can take one from black as example. (Not saying you should do this, just presenting this as a reason against).

specific linter then we should try to ensure those lints pass

Yes, the only supported version is the one installed by CI. Obviously we can't support future versions that may not have been released yet or even written.

errors being introduced in the future

Yes, so fixing this without enforcement seems doubly-bad. (Again, not saying you should do this, just presenting this as another reason against).

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look at the number of conflict, see also my template answer:

Thank you for your contribution. While this stylistic change makes sense on its own, it comes at a cost and risk for the project as a whole. The weak motivation for the change does not justify the burden that it places on the project. A burden could be any of the following:

  • Time spent on review
  • Accidental introduction of bugs
  • (Silent) merge conflicts, either in the branch or a backport branch. Those conflicts demand further developer and reviewer time or introduce bugs.

For more information about refactoring changes and stylistic cleanup, see

Generally, if the style is not mentioned nor enforced by the developer notes, we leave it up to the original author to pick whatever fits them best personally and then leave it that way until the line is touched for other reasons.

Let me know if you have any questions.

@@ -81,7 +81,7 @@ def witness_script_test(self):
# Create a new P2SH-P2WSH 1-of-1 multisig address:
eckey = ECKey()
eckey.generate()
embedded_privkey = bytes_to_wif(eckey.get_bytes())
embedded_privkey = bytes_to_wif (eckey.get_bytes())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure this is wrong.

@willcl-ark
Copy link
Member Author

OK thanks.

Well, I'll switch this to use git files and makes sure it passes CI and leave it as an option vs #26257.

@@ -72,7 +72,7 @@ def create_transaction(self, *, txid, input_details=None, addr, amount, privkey)
def run_test(self):
eckey = ECKey()
eckey.generate()
self.privkey = bytes_to_wif(eckey.get_bytes())
self.privkey = bytes_to_wif (eckey.get_bytes())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these seem to be matched by accident by the if( regex

-BEGIN VERIFY SCRIPT-
git grep -l "\ assert(" -- '*.py' | grep -v "src/" | xargs sed -i 's/\ assert(/\ assert\ (/g'
git grep -l "\ not(" -- '*.py' | grep -v "src/" | xargs sed -i 's/\ not(/\ not\ (/g'
git grep -l "\ if(" -- '*.py' | grep -v "src/" | xargs sed -i 's/\ if(/\ if\ (/g'
-END VERIFY SCRIPT-
@willcl-ark
Copy link
Member Author

Thank you for your contribution. While this stylistic change makes sense on its own, it comes at a cost and risk for the project as a whole. The weak motivation for the change does not justify the burden that it places on the project.

OK. I will just apply the patch locally as I'm using newer flake8.

@willcl-ark willcl-ark closed this Nov 8, 2022
@maflcko
Copy link
Member

maflcko commented Nov 8, 2022

No objection, if you want to bump the CI version and add the rule to the excludes. Should be non-controversial.

flake8 to 5.0.4
mypy to 0.971
pyzmq to 24.0.1
vulture to 2.6
@willcl-ark
Copy link
Member Author

OK I can re-open with a bump to the CI in case the scripted diff is preferred over #26257

@willcl-ark willcl-ark reopened this Nov 8, 2022
@jonatack
Copy link
Member

jonatack commented Nov 8, 2022

This seems less pythonic and at first glance I'm not sure why it would be a better solution than the PR with two ACKs. I do think it's preferable to give review feedback than open competing PRs.

@maflcko
Copy link
Member

maflcko commented Nov 8, 2022

I said "add the rule to the excludes" should be uncontroversial, not the scripted-diff, which is still broken in many ways, as I pointed out already.

@willcl-ark
Copy link
Member Author

Ah OK I understand. I will review the PR from @jonatack which I agree, without the brackets, is more pythonic.

@willcl-ark willcl-ark closed this Nov 8, 2022
@maflcko
Copy link
Member

maflcko commented Nov 8, 2022

E301, E302, E303, ... and others aren't enforced either, so why would E275 be important enough to enforce?

@willcl-ark
Copy link
Member Author

When python was bumped to 3.6.15 I made a new venv, installed flake8 et. al. (with a simple pip install flake8 -- not using the pinned versions from ci/lint/04_install.sh) and ran the linter, which resulted in the E275 errors that this change fixed, but no E301, E302, E303, ... errors. So I suppose newer flake8 is checking E275 by default?

I'm not sure if we expect people to manually extract and locally install pinned versions from that ci script (it is linked from the readme), add a requirements.txt to test/, or leave the status quo. But I suspected I would not be the only person to encounter this (and had I used GitHub's search function like a good netizen I would have seen I was correct without needing to open this conflicting PR!)

@maflcko
Copy link
Member

maflcko commented Nov 8, 2022

Yes, it is mentioned in the readme. Improvements are welcome, if there are any.

@bitcoin bitcoin locked and limited conversation to collaborators Nov 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants