-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
MNT Enforce ruff rules (RUF) #30694
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
MNT Enforce ruff rules (RUF) #30694
Conversation
2d924a4
to
69b657d
Compare
Thanks for the PR @DimitriPapadopoulos. These rules mostly summarize to ordering
|
Of course, I can enable The useless |
ce9a5d8
to
61501d4
Compare
@DimitriPapadopoulos I think you have contributed useful stuff in the past to the project, thanks a lot 🙏! In this case it looks like you opened multiple PRs on separate aspects on cleaning up/maintenance. Sometimes splitting PRs is good, and sometimes as a busy maintainer it can feel a bit too much. I would suggest you keep only one PR open and close the others, the one you think is the most important, wait for feed-back, iterate until it is merged, and then open another PR ... My personal opinion on this kind of PRs, is that they don't have huge benefits and they tend to be controversial. People will have different opinions on whether it is worth it or not, and at the end significant reviewer and contributor time has been spent on something that probably was not so crucial for the project and this time could have been invested somewhere else with a more useful outcome ... |
@lesteve Other maintainers insist on smaller PRs - tastes and colors. While it's possible to discuss individual rules, linters do result in more maintainable code overall, and sometimes find actual bugs. Perhaps the benefit is not huge, but the cost is small. As for the controversial part of rules, choosing a mainstream linter (or formatter) gets controversy out of the way. As for closing the PRs, now that they're already opened, I don't know. |
61501d4
to
6464e56
Compare
warning: Invalid `# noqa` directive: expected `:` followed by a comma-separated list of codes (e.g., `# noqa: F401, F841`).
RUF010 Use explicit conversion flag
RUF015 Prefer `next(...)` over single element slice
RUF017 Avoid quadratic list summation
RUF021 Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear
RUF022 `__all__` is not sorted
RUF100 Unused blanket `noqa` directive
RUF002 Docstring contains ambiguous ` ` (NO-BREAK SPACE). Did you mean ` ` (SPACE)?
1511480
to
0aec43b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a reviewer, it is a lot of different types of changes to go through. I think if we want to enforce more linting rules, it's best to introduce them one at a time. i.e. One small PR on sorting __all__
, one on removing unncessary # noqa
, etc and slowly introduce them one at a time.
In any case, given we already have this PR, I'm okay with enforcing the proposed rules.
@@ -341,7 +341,7 @@ def euclidean_distances( | |||
|
|||
Notes | |||
----- | |||
To achieve a better accuracy, `X_norm_squared` and `Y_norm_squared` may be | |||
To achieve a better accuracy, `X_norm_squared` and `Y_norm_squared` may be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can not tell what this change is. A unicode character?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With a single commit per rule, there's the workaround of reviewing the commits individually.
In this case, I manually changed a NO-BREAK SPACE U+00A0 into a regular SPACE U+0020 in 0aec43b, to silence ambiguous-unicode-character-docstring (RUF002).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. You need to add a this to .git-blame-ignore-revs
after merging this.
Do you expect me to add the commits to Note however that while these are mostly automatic ruff fixes, I manually fixed some issues. |
Yes, we prefer to completely ignore styling changes to keep the blame relevant in case we need to know who worked on a feature. |
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695)
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695)
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695)
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695)
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695) * black → ruff format (scikit-learn#31015)
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695) * black → ruff format (scikit-learn#31015)
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695) * black → ruff format (scikit-learn#31015)
* Enforce ruff rules (RUF) (scikit-learn#30694) * Apply ruff/flake8-implicit-str-concat rules (ISC) (scikit-learn#30695) * black → ruff format (scikit-learn#31015)
What does this implement/fix? Explain your changes.
Enforce Ruff-specific rules (RUF) rules.
Any other comments?
Some rules have been disabled: either they don't seem that interesting, or they change too much of the codebase.
[doc skip]