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

Trailing comma in a dict in function call split all parameters #2672

Closed
char101 opened this issue Dec 5, 2021 · 4 comments
Closed

Trailing comma in a dict in function call split all parameters #2672

char101 opened this issue Dec 5, 2021 · 4 comments
Labels
F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?

Comments

@char101
Copy link
Contributor

char101 commented Dec 5, 2021

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:

db.insert('table', {'a': 10, 'b': 11})

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.

db.insert(
    'table',
    {
        'a': 10,
        'b': 11,
    },
)

Desired style

A more compact format could be this which only consumes 3 lines.

db.insert('table', {
    'a': 10,
    'b': 11,
})

Which is, black could only split the dictionary without affecting the function parameters.

@char101 char101 added the T: style What do we want Blackened code to look like? label Dec 5, 2021
@ichard26 ichard26 added the F: linebreak How should we split up lines? label Dec 5, 2021
@felix-hilden
Copy link
Collaborator

Definitely related to #1811, although this is a case of manually applying the magic trailing comma.

@ehiggs
Copy link

ehiggs commented Mar 10, 2022

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.

@JelleZijlstra
Copy link
Collaborator

@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.

@hauntsaninja
Copy link
Collaborator

I think OP's request is basically not to have the magic trailing comma. You can accomplish this by using --skip-magic-trailing-comma. The rest of OP's request is a duplicate of #1811

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

6 participants