-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[ruff
] Mark fixes for unsorted-dunder-all
and unsorted-dunder-slots
as unsafe when there are complex comments in the sequence (RUF022
, RUF023
)
#14560
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF022 | 18 | 2 | 0 | 0 | 16 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+3 -0 violations, +0 -16 fixes in 5 projects; 50 projects unchanged)
DisnakeDev/disnake (+0 -0 violations, +0 -2 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- disnake/interactions/application_command.py:15:11: RUF022 [*] `__all__` is not sorted + disnake/interactions/application_command.py:15:11: RUF022 `__all__` is not sorted
apache/airflow (+0 -0 violations, +0 -2 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
- airflow/__init__.py:63:11: RUF022 [*] `__all__` is not sorted + airflow/__init__.py:63:11: RUF022 `__all__` is not sorted
pandas-dev/pandas (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ pandas/api/typing/__init__.py:36:11: RUF022 `__all__` is not sorted
python/typeshed (+2 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W
+ stubs/lupa/lupa/__init__.pyi:3:11: RUF022 `__all__` is not sorted + stubs/setuptools/distutils/command/__init__.pyi:22:11: RUF022 `__all__` is not sorted
astropy/astropy (+0 -0 violations, +0 -12 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
- astropy/cosmology/__init__.py:30:11: RUF022 [*] `__all__` is not sorted + astropy/cosmology/__init__.py:30:11: RUF022 `__all__` is not sorted - astropy/cosmology/flrw/__init__.py:4:11: RUF022 [*] `__all__` is not sorted + astropy/cosmology/flrw/__init__.py:4:11: RUF022 `__all__` is not sorted - astropy/cosmology/realizations.py:9:11: RUF022 [*] `__all__` is not sorted + astropy/cosmology/realizations.py:9:11: RUF022 `__all__` is not sorted - astropy/cosmology/units.py:19:11: RUF022 [*] `__all__` is not sorted + astropy/cosmology/units.py:19:11: RUF022 `__all__` is not sorted - astropy/io/fits/hdu/base.py:32:11: RUF022 [*] `__all__` is not sorted + astropy/io/fits/hdu/base.py:32:11: RUF022 `__all__` is not sorted - astropy/logger.py:32:11: RUF022 [*] `__all__` is not sorted + astropy/logger.py:32:11: RUF022 `__all__` is not sorted
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
RUF022 | 19 | 3 | 0 | 0 | 16 |
The ecosystem changes look good to me. |
charliermarsh
approved these changes
Nov 24, 2024
…ots` as unsafe when there are complex comments in the sequence (`RUF022`, `RUF023`)
AlexWaygood
force-pushed
the
alex/unsafe-sorting
branch
from
November 24, 2024 12:43
57568f1
to
183ae3e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #14552
Mark fixes for
RUF022
as unsafe if there are own-line comments in__all__
, since these are often used to delimit categories within__all__
:Also mark the fix as unsafe if there are ambiguous cases like the following, where you can't say for sure which item the comment should be attached to when the items are reordered:
Also apply the same changes to
RUF023
(which sorts__slots__
rather than__all__
, and adjust the documentation for both rules accordingly.Test Plan
cargo test -p ruff_linter --lib
.I went through all the existing fixtures for these two rules. All the examples which I would expect to be marked as unsafe fixes are now marked accordingly. All the ones that I would expect to still be marked as safe are still marked as safe.
We already have very good fixture coverage for these rules, so I didn't add any new fixtures.