-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
A single conditional expression inside a list is unnecessarily parenthesized #3545
Comments
I agree. |
Why are we adding a paranthesis pair, in which case would it be useful? |
I got a related case which does not use a list: first (shorter) case:black output for some_long_variable_name = True
abc = round(
(
1234.5678
if some_long_variable_name
else 12345.678 if not some_long_variable_name else 123456.78
),
1,
) I'd expect and prefer this: some_long_variable_name = True
abc = round(
1234.5678
if some_long_variable_name
else 12345.678 if not some_long_variable_name else 123456.78,
1,
) second case:black output for some_very_very_very_veeeeeeeeeeeeery_long_condition_to_check = True
abc = round(
(
1234.5678
if some_very_very_very_veeeeeeeeeeeeery_long_condition_to_check
else (
12345.678
if not some_very_very_very_veeeeeeeeeeeeery_long_condition_to_check
else 123456.78
)
),
1,
) I'd expect and prefer this: some_very_very_very_veeeeeeeeeeeeery_long_condition_to_check = True
abc = round(
1234.5678
if some_very_very_very_veeeeeeeeeeeeery_long_condition_to_check
else (
12345.678
if not some_very_very_very_veeeeeeeeeeeeery_long_condition_to_check
else 123456.78
),
1,
) |
@yilei I've opened #4312 that fixes this issue. I added it under the It's also worth noting that the current items = [(
{'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}
if some_var == 'longstring'
else {'key': 'val'}
)] which is better than the stable style, but could still be improved. I took a look at the examples @mariuswallraff provided, but I believe that change was the intention of #2278 in the first place, based off the test cases it adds. |
Thank you for the fix and for having a look at my post. After reading the other pull request and issue again, I have to agree with you, that change was intentional for the cases I posted. I'll have to get used to the extra indent. 😄 |
Describe the style change
Examples in the current Black future style
Desired style
Additional context
This is a change from #2278.
I think for this edge case, it shouldn't be parenthesized which also adds an extra indentation level.
Playground link: https://black.vercel.app/?version=stable&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ADgAI9dAD2IimZxl1N_Wlw1a7WWyFbt4o765uThnUap6YXDKg-y2hZjBQk1tHkIJUmRf3ubZW6qh6rwYiTz123BJex-bSSddR0SO6n6vZGd9BpWqXFwR2_6FGijjM_Dne5AzdiE1FlCq8_2Dsx5LlvLchM8KOQsFr8WMFH9R1i7Ks2Es0D6bZmm7Cl6fnGsY_a6uEkAAACpTN_YLIf7gwABqwHhAQAAKlDv4rHEZ_sCAAAAAARZWg==
The text was updated successfully, but these errors were encountered: