-
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
RUF022 autofix should be marked unsafe if there are own-line comments between __all__
items
#14552
Comments
Thanks for opening this issue. Comments are difficult to get right because they have no semantic meaning. Is I see two possible changes instead of removing the fix entirely:
__all__ = [
# Core components
"TaskManager",
"TaskExecutor",
# Models
"TaskContext",
"TaskProvider",
"TaskResult",
# Utilities
"execute_concurrent",
] Is formatted to __all__ = [
# Core components
"TaskExecutor",
"TaskManager",
# Models
"TaskContext",
"TaskProvider",
"TaskResult",
# Utilities
"execute_concurrent",
] I'm sure @AlexWaygood has some thought |
Thanks for opening the issue @phil65! There's already some extensive documentation on the fix safety of this rule at https://docs.astral.sh/ruff/rules/unsorted-dunder-all/#fix-safety, and we note this problem there. However, I'm open to making this fix unsafe if there are any own-line comments. I think that's in the spirit of the policy on fix safety we recently adopted when it comes to comments. We should make the same change to
Unfortunately doing this would make the rule incompatible with the formatter, because the formatter will remove blank lines in between the items, which would then lead to the rule applying a different sort to the items than if the blank lines were present. |
Right, I think we even discussed this back then. Thanks for reminding me. |
__all__
items
Thank you for quick handling and a great piece of software. :) |
__all__
, couldnt see anything from today.Since 0.8.0, ruff wants to sort my
__all__
array.Thats generally very nice, but it also messes up something like.
gets sorted to:
So it messes up the groups.
Comments are only attached to one item instead of the group when sorting. I am not sure if that is a good assumption. Perhaps ignore sorting it when comments are inside the all array?
Thanks! :)
The text was updated successfully, but these errors were encountered: