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

Inconsistent method chaining #1723

Closed
rvinzent opened this issue Sep 23, 2020 · 3 comments
Closed

Inconsistent method chaining #1723

rvinzent opened this issue Sep 23, 2020 · 3 comments
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?

Comments

@rvinzent
Copy link

rvinzent commented Sep 23, 2020

black currently formats method chaining inconsistently. It should always produce the more readable option.

Examples in the current Black style
This is ugly and hard to read:

This occurs only sometimes

def get_queryset(self):
    return SomeModel.objects.filter(
        related__field=self.kwargs["field"]
    ).prefetch_related("one_field")

With longer method chaining, the more readable format is generated:

    def get_queryset(self):
        return (
            SomeModel.objects.filter(related__field=self.kwargs["field"])
            .prefetch_related("one_field")
            .select_related()
        )

Desired style:
It would be nice if the more readable format was always produced in the first case above. It would be easier to read and more consistent.

def get_queryset(self):
    return (
        SomeModel.objects
        .filter(related__field=self.kwargs["field"])
        .prefetch_related("one_field")
    )

On a related note, sometimes method chains are broken up in a way that harms readability, the suggested format above would be auto-formatted to a less readable version below

def get_queryset(self):
    return SomeModel.objects.filter(related__field=self.kwargs["field"].prefetch_related(
        "one_field"
    )

The desired format would be the same in this case, as it is clearly more readable to have arguments appear next to the functions they are passed to.

@rvinzent rvinzent added the T: style What do we want Blackened code to look like? label Sep 23, 2020
@JelleZijlstra JelleZijlstra added the F: linebreak How should we split up lines? label May 30, 2021
@felix-hilden
Copy link
Collaborator

This is being discussed in #571, so I'll close this as a duplicate.

@felix-hilden felix-hilden added the R: duplicate This issue or pull request already exists label Feb 1, 2022
@rvinzent
Copy link
Author

rvinzent commented Feb 1, 2022

This is being discussed in #571, so I'll close this as a duplicate.

Ah sorry for missing that. Is there any recent movement on the issue?

@felix-hilden
Copy link
Collaborator

No worries! Yes there has been.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants