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

Odd formatting with split ternary in dict literal #172

Closed
ojii opened this issue Apr 26, 2018 · 1 comment
Closed

Odd formatting with split ternary in dict literal #172

ojii opened this issue Apr 26, 2018 · 1 comment

Comments

@ojii
Copy link
Contributor

ojii commented Apr 26, 2018

Operating system: mac OS 10.13.4 (High Sierra)
Python version: 3.6.5
Black version: 1445bea
Does also happen on master: Yes

Given this input:

data = {
    "a": compute_a_value_this_is_so_long() if some_condition_long_condition else compute_another_value(),
    "b": 10
}

Black gives me:

data = {
    "a": compute_a_value_this_is_so_long()
    if some_condition_long_condition
    else compute_another_value(),
    "b": 10,
}

The if and else on the same indentation level as the keys looks very odd and hard to parse at a glance to me. Moving it up one level and possibly adding parens makes it easier to read/prettier to me.

data = {
    "a": (
        compute_a_value_this_is_so_long()
        if some_condition_long_condition
        else compute_another_value()
    ),
    "b": 10,
}

Of course this is not the only solution and maybe others think the current code is okay. Just my 2 cents.

@zsol
Copy link
Collaborator

zsol commented Apr 26, 2018

Thanks for reporting! This looks like it boils down to the same issue as #147

@zsol zsol closed this as completed Apr 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants