Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for #551: fix minor flake8 complaints #552

Merged
merged 23 commits into from Dec 3, 2022
Merged

PR for #551: fix minor flake8 complaints #552

merged 23 commits into from Dec 3, 2022

Conversation

edreamleo
Copy link
Contributor

@edreamleo edreamleo commented Nov 28, 2022

See #551.

  • (Off topic, but harmless) Add .pylintrc for close control over pylint.
  • Suppress two flake8 warnings in setup.cfg:
    • B007: Loop control variable 'whatever' not used within the loop body.
    • B011: Do not call assert False. Instead raise AssertionError()
  • Add a blank line at the end of setup.py.
  • Fix intermixed tabs and spaces in ropetest/contrib/autoimport/utilstest.py.
  • Remove extra blank lines in ropetest/contrib/autoimport/utilstest.py.
  • Add a comment that leading blank lines are necessary in a docstring in ropetest/type_hinting_test.py.
  • Fix the following flake8 warnings:
    • B009: Do not call getattr with a constant attribute value.
    • E722: Do not use bare except, specify exception instead.
    • E741: ambiguous variable name 'l'.
    • F541: f-string without any placeholders.
    • NQA101: "# noqa" has no violations.

@edreamleo edreamleo marked this pull request as draft November 28, 2022 15:02
@lieryan
Copy link
Member

lieryan commented Nov 28, 2022

Fix intermixed tabs and spaces in ropetest/contrib/autoimport/utilstest.py. I don't understand why neither reindent nor black complained

black is disabled on ropetest folder, because black's treatment of multi-line string with textwrap.dedent() is horrendous and the ropetest folder uses a lot of textwrap.dedent() and multiline strings.

If you want to run black on the ropetest folder, you're going to want to use a specific patch of black, and then adjust black's force-exclude in pyproject.toml. ropetest has been excluded by default so that people don't screw up all the formatting by running normal black on ropetest folder.

@edreamleo edreamleo marked this pull request as ready for review November 28, 2022 23:11
@edreamleo edreamleo marked this pull request as draft November 28, 2022 23:11
@edreamleo
Copy link
Contributor Author

edreamleo commented Nov 28, 2022

@lieryan Thanks for the heads up about black.

rope/refactor/move.py Outdated Show resolved Hide resolved
@lieryan lieryan added the cleanup Code quality issues. Linter, type checking, Python 2-ism, Pythonic, etc label Dec 1, 2022
@edreamleo edreamleo marked this pull request as ready for review December 1, 2022 11:50
rope/refactor/patchedast.py Outdated Show resolved Hide resolved
@@ -181,7 +181,7 @@ def logical_line_in(self, line_number):
indents = count_line_indents(self.lines.get_line(lineno))

def generate_starts(self, start_line=1, end_line=None):
for start, end in self.generate_regions(start_line, end_line):
for start, _end in self.generate_regions(start_line, end_line):
Copy link
Member

Choose a reason for hiding this comment

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

Having a convention where unused variable have to be prefixed with underscore (e.g. _varname) isn't going to be enforceable unless we run a linter scanning for this as pre-commit or as a Github Actions; it's too easy to miss that during manual code review. I'd rather we either disable this warning in local linter or add at least a Github Actions to enforce this.

Copy link
Contributor Author

@edreamleo edreamleo Dec 2, 2022

Choose a reason for hiding this comment

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

flake8 was the source of the complaints. Is it hard to check commits with flake8?

Similarly, it might be good to add a GitHub action that checks that reindent does nothing on all files, including those in the ropetest directory.

Otoh, B007 is a "bugbear" for good reason. I would be happy to disable it in setup.cfg.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

B007 is is now disabled. We can revisit this question at our leisure.

Copy link
Member

Choose a reason for hiding this comment

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

reindent does nothing on all files, including those in the ropetest directory.

We have Black running on GitHub Actions for formatting checks. I think that should be sufficient, adding more than one formatter would be undesirable, IMO, as it creates the possibility of conflicting advices from the tools.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know.

@lieryan
Copy link
Member

lieryan commented Dec 2, 2022

Hi @edreamleo, I think this is about the right size for a PR to be reviewable, any bigger and this will become hard to review the code. Can we freeze this PR at this stage (so any further commits should only be to address things raised during the review), and split any further fixes as separate PR?

@edreamleo
Copy link
Contributor Author

@lieryan I agree that this PR should not be bigger.

I am willing to close this PR and start a new PR from scratch with the B007 check disabled. A new PR might be best in the long run if you are uncomfortable with adding leading underscores. It's your call.

I'm not sure about my own preferences. I think pylint will catch most blunders re B007, but I wouldn't bet my life on it :-)

@edreamleo
Copy link
Contributor Author

edreamleo commented Dec 2, 2022

@lieryan There is no need for me to create a new PR. It's easy for me to revert specific lines, and the diffs in this PR will confirm that the net changes are as I intended.

@edreamleo
Copy link
Contributor Author

@lieryan After further thought, I'd like to delete the added underscores and suppress B007 for now. This will shorten this PR and delay a final decision for (much?) later.

@edreamleo
Copy link
Contributor Author

@lieryan The diffs now show no added underscores in loop vars. Imo, this PR should now be good to merge.

Copy link
Member

@lieryan lieryan left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @edreamleo!

@lieryan lieryan merged commit 7451194 into python-rope:master Dec 3, 2022
@edreamleo edreamleo deleted the ekr-flake8 branch December 3, 2022 10:18
@edreamleo
Copy link
Contributor Author

@lieryan You're welcome. I am enjoying our collaboration!

@lieryan lieryan added this to the 1.6.0 milestone Dec 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cleanup Code quality issues. Linter, type checking, Python 2-ism, Pythonic, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants