-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Keep single-line signatures when body is an Ellipsis (...
) in .py
files
#10026
Comments
Thanks for the excellent writeup! We've implemented your desired behavior but it's currently only applied when you format your code with We hope to promote the new formatting to stable in this month, but you can already start using it if you enable Let me know if that works for you |
Hello, thanks for you answer! I ran a [tool.ruff.format]
preview = true It puts back the Ellipses back on their single line 👍 However, it also brings new changes, mainly compressing multiple braces in a javascript formatting style. Excerpt from the xarray repo: - self.ds = Dataset(
- {
- "a": (("x", "y"), np.ones((300, 400))),
- "b": (("x", "y"), np.ones((300, 400))),
- }
- )
+ self.ds = Dataset({
+ "a": (("x", "y"), np.ones((300, 400))),
+ "b": (("x", "y"), np.ones((300, 400))),
+ }) Even though I personally like this new formatting (it looks like javascript formatting, is more concise, and saves a level of indentation), I would still like to get more granularity inside of the According to the documentation of Preview we can select rules for the linter with Thanks! |
That makes sense. There's no such granular opt-in to preview formatting. It's all or nothing, similar to the formatter itself which only provides very few configuration nobs. For preview, this is especially important because it ensures that users give feedback to all preview styles and don't just disable the styles they don't like. It prevents situations where all users disabled a controversial style change but we decide releasing it because we never received any negative feedback on the style. |
Okay, I fully understand the point of having a single preview style! Thanks a lot for the help on that topic! |
I'll close this issue. You can follow #8678 to get notified when we promote the new preview styles (The style you're calling out won't be promoted) |
thanks to astral-sh/ruff#10026 for suggestion on keeping single line Ellipsis
A minimal code snippet that reproduces the bug.
File name:
format_ruff.py
Before ruff:
After ruff:
The command you invoked
Note: in real-life scenario, one might have installed the Ruff extension on VSCode, opened a file with many stubs like in the minimal code snippet, and see them all formatted, introducing unwanted code change, which can be annoying for version control.
This might also slow down ruff adoption in existing large code bases where the case mentioned above happens a lot.
The current Ruff settings
No overriden settings. I ran a
pip install ruff
then ran the command aboveThe current Ruff version
What I would like
A way to opt-out of de-inlining the Ellipsis (
...
) in stubs. I have searched in documentation without finding such an option. I browsed the following issues (in Links section).An option could be:
Links
Related Issues:
.pyi
files, not.py
; I would like the option to be activable for all types of files.Related PRs:
.pyi
files, but maybe it could be generalized to.py
?)Thanks!
The text was updated successfully, but these errors were encountered: