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

Break outer expressions before sub-expressions #2894

Closed
ktbarrett opened this issue Feb 22, 2022 · 1 comment
Closed

Break outer expressions before sub-expressions #2894

ktbarrett opened this issue Feb 22, 2022 · 1 comment
Labels
T: style What do we want Blackened code to look like?

Comments

@ktbarrett
Copy link
Contributor

Describe the style change

When an long expression contains function calls and joining operators black will choose to break the function call if the arguments exceeds the maximum line length. This can look pretty ugly. Instead, I think that black should break the outmost (least nested) parts of the expressions before inner parts of the expression.

Examples in the current Black style

    def parse_assign_stmt(self) -> Optional[ast.AssignStmt]:
        if isinstance(name := self._lookahead(1), ast.Name) and isinstance(
            assign := self._lookahead(2), ast.Assign
        ):
            ...

Desired style

    def parse_assign_stmt(self) -> Optional[ast.AssignStmt]:
        if (
            isinstance(name := self._lookahead(1), ast.Name)
            and isinstance(assign := self._lookahead(2), ast.Assign)
        ):
            ...

This will improve clarity in general as all "levels" of the expression will occur at the same level of indentation.

@ktbarrett ktbarrett added the T: style What do we want Blackened code to look like? label Feb 22, 2022
@ktbarrett
Copy link
Contributor Author

ktbarrett commented Feb 22, 2022

Ah, just found #2156, closing as this is a dupe.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

1 participant