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

how to comprehension black split []? #2566

Closed
Cherrymelon opened this issue Oct 26, 2021 · 5 comments
Closed

how to comprehension black split []? #2566

Cherrymelon opened this issue Oct 26, 2021 · 5 comments
Labels
T: style What do we want Blackened code to look like?

Comments

@Cherrymelon
Copy link

Describe the style change
i found black will split arr[1] to a wired format

Examples in the current Black style

some_arr[
1
]

Desired style

some_arr[1]

Additional context

@Cherrymelon Cherrymelon added the T: style What do we want Blackened code to look like? label Oct 26, 2021
@JelleZijlstra
Copy link
Collaborator

That is not in fact how Black formats that code normally. Perhaps you have a very long key. Could you provide more details?

@Cherrymelon
Copy link
Author

here is detail

                        box["property"] = LineItem(category, key, "table", value.page_index)
                        box["item"] = project_name
                        if project_name.value:
                            span = project_name.value.lines[
                                -1
                            ]._LocationTextPart__location["spans"]
                            if span:
                                uniq_name = "{}_{}_{}".format(
                                    project_name.value._LocationText__str,
                                    project_name.value.lines[
                                        -1
                                    ]._LocationTextPart__location["spans"][0]["bbox"][
                                        0
                                    ],
                                    project_name.value.lines[
                                        -1
                                    ]._LocationTextPart__location["spans"][0]["bbox"][
                                        1
                                    ],
                                )

@rmorshea
Copy link

rmorshea commented Nov 4, 2021

This seems like another example of: #2156

@felix-hilden
Copy link
Collaborator

felix-hilden commented Nov 4, 2021

Indeed, and also related to #571 because of the dotted names, although I couldn't find an issue on the tracker that combines fluent interfaces with subscript access. I'd expect the formatting to be:

if 1:
    if 1:
        if 1:
            box["property"] = LineItem(category, key, "table", value.page_index)
            box["item"] = project_name
            if project_name.value:
                span = (
                    project_name.value.lines[-1]
                    ._LocationTextPart__location["spans"]
                )
                if span:
                    uniq_name = "{}_{}_{}".format(
                        project_name.value._LocationText__str,
                        (
                            project_name.value.lines[-1]
                            ._LocationTextPart__location["spans"][0]["bbox"][0]
                        ),
                        (
                            project_name.value.lines[-1]
                            ._LocationTextPart__location["spans"][0]["bbox"][1]
                        ),
                    )

Since the last lines in the original example don't fit the line length, this is of course formatted further by exploding the subscripts. Sadly there isn't a fluent interface of subscripts.

@hauntsaninja
Copy link
Collaborator

Closing as a duplicate of #2156 and #1280

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
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

5 participants