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

Formatter collapses last call in call chaining #7051

Closed
cnpryer opened this issue Sep 1, 2023 · 3 comments · Fixed by #7767
Closed

Formatter collapses last call in call chaining #7051

cnpryer opened this issue Sep 1, 2023 · 3 comments · Fixed by #7767
Assignees
Labels
documentation Improvements or additions to documentation formatter Related to the formatter

Comments

@cnpryer
Copy link
Contributor

cnpryer commented Sep 1, 2023

I prefer the change, but reporting since it's a diff in a from-black migration.

Line-length: 88

Related: #5343

Black (23.7.0):

df.drop(
    columns=["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
).drop_duplicates().rename(
    columns={
        "a": "a",
    }
).to_csv(
    path / "aaaaaa.csv", index=False
)

Ruff (0.0.287):

df.drop(
    columns=["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
).drop_duplicates().rename(
    columns={
        "a": "a",
    }
).to_csv(path / "aaaaaa.csv", index=False)

Counter example

df.drop(
    columns=["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
).drop_duplicates(a).rename(
    columns={
        "a": "a",
    }
).to_csv(
    path / "aaaaaa.csv", index=False
).other(a)

Playground: https://play.ruff.rs/02424913-15b0-4703-8eb8-6bc5896b00b6

@cnpryer cnpryer changed the title Formatter removes last expanded call in call chaining Formatter un-expands last call in call chaining Sep 1, 2023
@charliermarsh charliermarsh added the formatter Related to the formatter label Sep 1, 2023
@MichaReiser
Copy link
Member

Black uses Ruff's formatting in preview style if the left is a multiline string but it seems they keep the old formatting otherwise playground

To me it's unclear if expanding the last call is intentional to improve readability. I'm inclined to keep Ruff's formatting because it achieves the goal of avoiding unnecessary horizontal lines but it depends on how frequent we run into this difference (although could be hard to fix)

@MichaReiser MichaReiser added the needs-decision Awaiting a decision from a maintainer label Sep 2, 2023
@MichaReiser MichaReiser added this to the Formatter: Beta milestone Sep 2, 2023
@cnpryer
Copy link
Contributor Author

cnpryer commented Sep 2, 2023

This was not frequent for me, but tbh I'm curious why. The pattern looks like it could be in some exploratory scripts we have.

I'll dig more next week.

@charliermarsh
Copy link
Member

We're going to mark this as a known deviation for now. We'll revisit based on user feedback, but it's not blocking for the beta. (We can close the issue itself for now once this is documented.)

@charliermarsh charliermarsh removed the needs-decision Awaiting a decision from a maintainer label Sep 27, 2023
@MichaReiser MichaReiser added the documentation Improvements or additions to documentation label Sep 27, 2023
@charliermarsh charliermarsh self-assigned this Sep 27, 2023
charliermarsh added a commit that referenced this issue Oct 2, 2023
## Summary

I missed this in the prior pass.

Closes #7051.
@cnpryer cnpryer changed the title Formatter un-expands last call in call chaining Formatter collapses last call in call chaining Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants