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

Make ruff much stricter #425

Merged
merged 30 commits into from
May 13, 2024
Merged

Make ruff much stricter #425

merged 30 commits into from
May 13, 2024

Conversation

jherland
Copy link
Member

Re-configure ruff to enable as many checks as feasible, and fix various issues throughout our codebase. The second PR in a series of 3.

Commits:

  • Re-configure ruff to be much stricter
  • Fix docstring issues
  • Fix unused method arguments
  • Fix set(<generator>) -> {<set comprehension>}
  • Fix variable shadowing Python builtin
  • Fix unused function arguments
  • Fix assert False -> pytest.fail(...)
  • Fix subprocess problems
  • Fix magic values used in comparisons
  • Fix use of non-tuples in @pytest.mark.parametrize
  • Fix ambiguous character in comment
  • Fix unnecessary use of .keys()
  • Fix unnecessary use of str()
  • Fix set([...]) -> {...}
  • Fix unnecessary None argument to .get()
  • Use ternary operator instead of if-else block
  • Use @pytest.fixture() over @pytest.fixture
  • Fix unecessary use of _ in parametrized args
  • Use Path.* methods where available
  • Avoid extraneous parentheses
  • Use yield from instead of for-loop with yield inside
  • Consolidate if-conditions
  • Use [foo, *bars] instead of [foo] + bars
  • Use elif instead of else + if where possible
  • Ensure bool flag arguments to functions are always named
  • Merge multiple comparisons
  • Rename UnparseablePathException -> UnparseablePathError
  • Ignore remaining/intentional violations of N818
  • Fix PTH201: Do not pass the current directory explicitly to Path()

@jherland jherland self-assigned this Apr 16, 2024
@jherland jherland requested review from mknorps and zz1874 April 16, 2024 07:32
Base automatically changed from jherland/add-ruff to main May 6, 2024 12:36
@jherland jherland force-pushed the jherland/make-ruff-strict branch from 98102f3 to ac3999a Compare May 6, 2024 12:38
@jherland jherland force-pushed the jherland/make-ruff-strict branch from ac3999a to 17eae72 Compare May 6, 2024 12:49
Copy link
Collaborator

@mknorps mknorps left a comment

Choose a reason for hiding this comment

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

I really like how you logically structured the problem making ruff strict - each commit tackling a different type of error.

I think we should avoid # noqa comment as much as possible, or explain why we use it, but this can be a subject of another PR.

🚀

@jherland
Copy link
Member Author

I really like how you logically structured the problem making ruff strict - each commit tackling a different type of error.

Thanks! 🙏🏻

I think we should avoid # noqa comment as much as possible, or explain why we use it, but this can be a subject of another PR.

Agreed. My philosophy here is roughly this:

  • Enable all ruff checks by default, with the following exceptions:
  • If there is a ruff check that we don't want, or that ruff itself discourages, then disable it in pyproject.toml with a comment explaining why.
  • If there is a ruff check that we would like to follow, but that (a) requires a bigger effort to fix, or (b) touches a lot of our code, then disable it in pyproject.toml for now, and explain that we will get around to it later.
  • Otherwise, add a # noqa comment for the issues that we will either get around to later, or that we find "acceptable" to live with indefinitely.

With these pytlint -> ruff PRs, we've gone from ~30 # noqa and # pylint comments before to ~60 # noqa comments after these PRs. Most of this is because ruff simply has more checks to push our code into a better shape, overall.

An important goal is of course to minimize the number of # noqa comments, and to that end, I look very critically at # noqa comments that I encounter while refactoring code. But trying to fix them all in this PR is not feasible. As long as there is a general trend towards decreasing these, I'm happy.

@jherland jherland merged commit 1061f1d into main May 13, 2024
63 checks passed
@jherland jherland deleted the jherland/make-ruff-strict branch May 13, 2024 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants