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
Trailing comma in a dict in function call split all parameters #2672
Comments
Definitely related to #1811, although this is a case of manually applying the magic trailing comma. |
This is a regression somewhere between 19.10b0 and 22.1.0 and affects a lot of users using mongo. In: db.my_collection.update({"_id": some_id}, {"$set": {"cool_field": 123}}) Out (unchanged): db.my_collection.update({"_id": some_id}, {"$set": {"cool_field": 123}}) In (trailing argument comma): db.my_collection.update({"_id": some_id}, {"$set": {"cool_field": 123}},) Out: db.my_collection.update(
{"_id": some_id},
{"$set": {"cool_field": 123}},
) In (trailing comma in the dicts): db.my_collection.update({"_id": some_id,}, {"$set": {"cool_field": 123,}}) Out: db.my_collection.update(
{
"_id": some_id,
},
{
"$set": {
"cool_field": 123,
}
},
) I say this is a regression because the purpose of black is to make one true formatting ™️ but the trailing commas influence the formatting a great deal. |
@ehiggs that's the magic trailing comma, which for better or for worse is Black's documented behavior now. It's separate from the original request in this issue. |
I think OP's request is basically not to have the magic trailing comma. You can accomplish this by using |
Describe the style change
When passing dict as a function parameter I often prefer than the dict is split in multiple lines while keeping other parameters in the same line.
Original code:
Examples in the current Black style
Adding a trailing comma in the dict results in all parameters split, consuming 7 lines, which feel too excessive in the vertical space usage.
Desired style
A more compact format could be this which only consumes 3 lines.
Which is, black could only split the dictionary without affecting the function parameters.
The text was updated successfully, but these errors were encountered: