-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Applying or ignoring RUF022
/RUF023
(__all__
& __slots__
sorting)
#13108
Conversation
RUF022
/RUF023
(__all__
& __slots__
sorting)
This comment has been minimized.
This comment has been minimized.
__slots__ = ( | ||
"namespace_whitelist", | ||
"save_debug_info", | ||
"function_aliases", | ||
"experimental_debug_stripper", | ||
"experimental_io_device", | ||
"experimental_variable_policy", | ||
"experimental_custom_gradients", | ||
"experimental_debug_stripper", | ||
"experimental_image_format", | ||
"experimental_skip_saver", | ||
"experimental_io_device", | ||
"experimental_sharding_callback", | ||
"experimental_skip_saver", | ||
"experimental_variable_policy", | ||
"extra_tags", | ||
"function_aliases", | ||
"namespace_whitelist", | ||
"save_debug_info", | ||
) |
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.
In case you're searching for it, this is the only RUF023
change
# TODO: Ruff 0.8.0 added sorting of __all__ and __slots_. Validate whether we want this in stubs | ||
"RUF022", | ||
"RUF023", | ||
|
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.
If we decide to ignore, these should go in the .pyi
-only ignores.
I'm actually sort-of surprised that stubtest isn't freaking out about |
This comment has been minimized.
This comment has been minimized.
As long as this doesn't affect stubtest's ability to verify which items are in |
I'm also +0 about this change. |
Is there an option to sort list-based |
I'd generally favor consistency with the runtime, but I don't really see any practical reason why the order should matter, so we might as well sort them. |
There isn't. I'd consider implementing such a feature at ruff (I'm a maintainer there), but it feels like a slightly niche thing for Ruff to add a configuration option for. (Outside of typeshed, who would use it? Would it be obvious to anybody why the option exists unless you're a stub author and typing expert?) |
I don't think there's a strong reason to treat list and tuple |
The thought crossed my mind as well. But I have to agree, it would be extremely niche. And would only apply to stubs (as to re-expose the same type). The general comment about fix safety from the rule's doc still applies to tuples. I thought about it some more over dinner, and I can't think of a single legitimate case where not only the order matters, but that you also can't deal with it programmatically (ie: getting all names that are in all-caps instead of the first 5 if you wanted the constants for example, and even that example isn't affected by tuple types). Like it would be so niche that you aren't looking at stubs/types anyway. |
I don't know the whole answer, but I stuck a breakpoint in stubtest. The |
This comment has been minimized.
This comment has been minimized.
I would somewhat prefer using the copy/paste order as is, so that stubs are closer to implementation. As already mentioned, this way it's much easier to see how a long |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
I feel like we should probably close this at this point (though we should probably get rid of the TODO comment in our |
I'm fine closing this. Edit: #13322 |
As per #13090 (comment), here's a PR to discuss whether we want
RUF022
in typeshed.From a typing perspective, this technically changes the type of tuple-literals
__all__
:Whilst the cases where this matters are extremely niche, there is an argument for accuracy.
Essentially the same thing is mentioned in https://docs.astral.sh/ruff/rules/unsorted-dunder-all/#fix-safety
Although is that's something we care about, stubtest could probably test for it, which would counter the "pros" of ordering consistency mentioned below as it would be enforced by stubtest and the order defined by implementation.
Another argument is about copying
__all__
from source. It might be easier to update/understand/debug if one can copy__all__
from implementation and the order stays the same.Arguments for applying
RUF022
is that autosorting and consistency are generally nice and after the initial commit help avoid conflicts. There's likely a few places in typeshed where we don't follow runtime ordering anyway.The same question and overall arguments also apply to
__slots__
sorting withRUF023