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

Don't always wrap in invisible parentheses #177

Closed
kalekseev opened this issue Apr 28, 2018 · 2 comments
Closed

Don't always wrap in invisible parentheses #177

kalekseev opened this issue Apr 28, 2018 · 2 comments
Labels
T: enhancement New feature or request

Comments

@kalekseev
Copy link
Contributor

Don't wrap multiline asserts into bracers if one part fits into one line and another already in brackets.

    data = [{
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
    }]
    assert data == [{
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
        "a": "b",
    }]

after black

+        data = [
+            {
+                "a": "b",
+                "a": "b",
+                "a": "b",
+                "a": "b",
+                "a": "b",
+                "a": "b",
+                "a": "b",
+                "a": "b",
+            }
+        ]
+        assert (
+            data
+            == [
+                {
+                    "a": "b",
+                    "a": "b",
+                    "a": "b",
+                    "a": "b",
+                    "a": "b",
+                    "a": "b",
+                    "a": "b",
+                    "a": "b",
+                }
+            ]
+        )

Can't we have same formatting for asserts as we have for assignments?

    assert data == [
        {
            "a": "b",
            "a": "b",
            "a": "b",
            "a": "b",
            "a": "b",
            "a": "b",
            "a": "b",
            "a": "b",
        }
    ]
@ambv
Copy link
Collaborator

ambv commented Apr 28, 2018

Yes, I agree with you. I will improve automatic parentheses handing, that will improve what's happening in this case, as well as other places currently auto-managed (if, elif, while, and so on). Then I can add it to assignments and dictionary values, too. Currently I admit it's a bit clumsy for most obvious examples (e.g. when there is just a single delimiter like the equals sign you're referring to.).

As for unpacking multiple brackets to separate indentation level, Black will continue doing this. I don't like multiple unrelated brackets shoved together to save a line.

@ambv ambv added the T: enhancement New feature or request label May 9, 2018
@ambv ambv changed the title Don't wrap multiline asserts into brackets Don't always wrap in invisible parentheses May 9, 2018
@ambv ambv added this to To Do in Getting to beta May 9, 2018
@ambv ambv moved this from To Do to In Progress in Getting to beta May 10, 2018
@ambv ambv closed this as completed in 5a47fd1 May 16, 2018
Getting to beta automation moved this from In Progress to Done May 16, 2018
@dhimmel
Copy link

dhimmel commented Oct 31, 2019

I think the original code, even after the extra parentheses were removed in the reformatted version, is the best. Specifically, I like:

    assert data == [{
        "a": "b",
        "a": "b",
    }]

More than:

    assert data == [
        {
            "a": "b",
            "a": "b",
        }
    ]

Putting [{ together avoids an extra level of indentation and saves two lines.

Here's an example from our codebase, where the compact format is preferred:

        args.extend([
            '--template-variables-path',
            str(manuscript_dir.joinpath('content/template-variables.json')),
        ])

Is there an option for this? Aware of any open issues on the matter? Or how I should title this request if opening a new issue requesting it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
No open projects
Development

No branches or pull requests

3 participants