Skip to content
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

Use black --preview for formatting. #12849

Closed
mcrumiller opened this issue Dec 1, 2023 · 4 comments
Closed

Use black --preview for formatting. #12849

mcrumiller opened this issue Dec 1, 2023 · 4 comments
Labels
enhancement New feature or an improvement of an existing feature

Comments

@mcrumiller
Copy link
Contributor

mcrumiller commented Dec 1, 2023

Description

Edit: looks like we don't use black anyway, but ruff's formatter which is a close equivalent, but doesn't yet support black's style. Not sure if this is feasible at the moment.


The black preview style can be enabled with the preview = true flag in our pyproject.toml file. Enabling this would (in my opinion) make a lot of the code more readable. Primarily, the improved multiline dictionary and list indentation makes this:

pl.DataFrame(
    {
        "a": [1, 2, 3],
        "b": [4, 5, 6],
    }
)

into this:

pl.DataFrame({
    "a": [1, 2, 3],
    "b": [4, 5, 6],
})

Which is much more concise and removes an entire level of indentation.

The drawback is of course that the preview style is subject to change, but I think the pros outweigh the cons.

@mcrumiller mcrumiller added the enhancement New feature or an improvement of an existing feature label Dec 1, 2023
@cmdlineluser
Copy link
Contributor

I think ruff just added this: astral-sh/ruff#8293

@stinodego
Copy link
Member

That would match what rustfmt does so I would be in favor. When ruff releases this along with their docstring formatter, we can have a nice big diff :)

@cmdlineluser
Copy link
Contributor

The previously mentioned pull request was in the ruff 0.1.7 release.

ruff 0.1.8 is out now and contains the docstring formatter.

https://astral.sh/blog/ruff-v0.1.8

@stinodego
Copy link
Member

We cannot use the docstring formatter yet because there is a bug in it. It was fixed and I hope to be able to use it when 0.1.9 comes out.

Regarding the preview style: we will just patiently wait for it to become stable, which should happen in ruff 0.2.0. There is no rush with this and we don't want to mess with the formatting more than needed. So I'll close this issue, but we will pick this up automatically when upgrading ruff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

3 participants