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

Unexpected formatting of subscript fluent interface #2920

Open
petersaalbrink opened this issue Mar 14, 2022 · 0 comments
Open

Unexpected formatting of subscript fluent interface #2920

petersaalbrink opened this issue Mar 14, 2022 · 0 comments
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?

Comments

@petersaalbrink
Copy link

Black version: 22.1.0

Suppose I have a deeply nested dict-like object:

data = {
    "long_key_name_0": {
        "long_key_name_1": {
            "long_key_name_2": {
                "long_key_name_3": {
                    "long_key_name_4": {
                        "long_key_name_5": {
                            "long_key_name_6": {
                                "long_key_name_7": {
                                    "long_key_name_8": {"long_key_name_9": {}}
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

If I access a nested value using a chained getitem expression (cf. fluent interface), Black formats the subscript notation in the following way:

value = data["long_key_name_0"]["long_key_name_1"]["long_key_name_2"][
    "long_key_name_3"
]["long_key_name_4"]["long_key_name_5"]["long_key_name_6"]["long_key_name_7"][
    "long_key_name_8"
][
    "long_key_name_9"
]

However, this would be my desired format:

value = (
    data
    ["long_key_name_0"]
    ["long_key_name_1"]
    ["long_key_name_2"]
    ["long_key_name_3"]
    ["long_key_name_4"]
    ["long_key_name_5"]
    ["long_key_name_6"]
    ["long_key_name_7"]
    ["long_key_name_8"]
    ["long_key_name_9"]
)

This issue is related to the following open issues:

However, since this issue is not exactly the same (as it is a combination between fluent interface and subscript notation), I decided to open a new issue for it.

Possible labels:

  • linebreak
  • design
  • parentheses
  • symmetry
@JelleZijlstra JelleZijlstra added the F: linebreak How should we split up lines? label Mar 14, 2022
@felix-hilden felix-hilden added the T: style What do we want Blackened code to look like? label Sep 11, 2022
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? T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants