-
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
no opinion on tuple assignment parentheses? #445
Comments
Agreed, this is something black should do in my opinion as well |
Agreed, I have this on my internal TODO list. |
I agree, but I also think we should add parentheses in places like this where the multiple assignment is too long to fit in one line. This tends to be pretty common in our codebase due to the way http://github.com/quora/asynq makes us do batching. So I would like to see @matejcik's first example become: (
a,
b,
c,
) = (
1,
2,
3,
) if the line otherwise becomes too long. |
I came here to report this because black will add, but not remove parentheses Example: value = some_really_really_really_long_variable_name_1, some_really_really_really_long_variable_name_2 becomes value = (
some_really_really_really_long_variable_name_1,
some_really_really_really_long_variable_name_2,
) but if you then shorten those names... value = (
name_1,
name_2,
) becomes value = (name_1, name_2) |
Just for clarity and to give another opinion, I'd expect the results to be: # all fits line
a, b, c = (d, e, f)
# too long overall but LHS fits line
a, b, c = (
d, e, f
)
# LHS too long but RHS fits line (always exploded fully)
(
a,
b,
c,
) = (d, e, f) Then if both are too long, we'd format as Jelle proposed, and then continue with the inner line breaks etc. Arguably, in the last case |
@felix-hilden could you please also clarify the following case when rhs is a function call? first_item, second_item = some_looooooooong_module.some_looooooooooooooong_function_name(
first_argument, second_argument, third_argument
) Currently black does: (
first_item,
second_item,
) = some_looooooooong_module.some_looooooooooooooong_function_name(
first_argument, second_argument, third_argument
) IMO the following is more readable: first_item, second_item = (
some_looooooooong_module.some_looooooooooooooong_function_name(
first_argument, second_argument, third_argument
)
) This is |
I would agree! |
This might be intentional but it feels like an omission, so I'm reporting it.
Does Black not have an opinion on parentheses around tuples, when assigning or returning? The following file remains untouched:
I would expect the optional parentheses would be removed in all above cases, per this: "In those cases, parentheses are removed when the entire statement fits in one line, or if the inner expression doesn't have any delimiters to further split on."
Operating system: Linux Mint
Python version: 3.6
Black version: 18.6b4
Does also happen on master: yes
The text was updated successfully, but these errors were encountered: