[ruff
] Mark fixes for unsorted-dunder-all
and unsorted-dunder-slots
as unsafe when there are complex comments in the sequence (RUF022
, RUF023
)
#14560
+219
−87
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.