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

Line splitting on conditional operators should take precendence over splitting on function parameters #1094

Open
ovidiu-munteanu opened this issue Oct 25, 2019 · 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

@ovidiu-munteanu
Copy link

Black should split conditionals at conditional operators (i.e. and, or, etc.) when possible, instead of splitting function parameters over multiple lines.

Currently, this is how black formats a long conditional:

if str(
    self.user.id
) != self.target_user_id and not CheckUserManagementViewPermission.user_has_permission(
    self.user
):
    pass

Ideally, it should be formatted like this:

if (
    str(self.user.id) != self.target_user_id
    and not CheckUserManagementViewPermission.user_has_permission(
        self.user
    )
):
    pass

This appears to be a general issue with splitting conditionals and it looks like it's related to these issues: #815 #1050

@ovidiu-munteanu ovidiu-munteanu added the T: style What do we want Blackened code to look like? label Oct 25, 2019
@ovidiu-munteanu ovidiu-munteanu changed the title Conditionals split on long identifier names makes it difficult to read Conditionals should split on conditional operators not on function parameters Oct 25, 2019
@ovidiu-munteanu ovidiu-munteanu changed the title Conditionals should split on conditional operators not on function parameters Line splitting on conditional operators should take precendence over splitting on function parameters Oct 25, 2019
@JelleZijlstra JelleZijlstra added the F: linebreak How should we split up lines? label May 30, 2021
@felix-hilden felix-hilden added the R: duplicate This issue or pull request already exists label Feb 1, 2022
@felix-hilden
Copy link
Collaborator

I'll close this as a duplicate of #2156, and add this specific case there.

@ambv
Copy link
Collaborator

ambv commented Feb 1, 2022

I'll re-open this because those cases are not the same. This case is for more than one operator in the mix.

@ambv ambv reopened this Feb 1, 2022
@felix-hilden
Copy link
Collaborator

felix-hilden commented Feb 1, 2022

Oh, fair enough 👍 at least they're linked now.

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

4 participants