The trailing comma is unnecessarily preserved when collapsing an inline dict that is a function argument, though not when the dict is in an assignment. Furthermore, a dict with a trailing comma isn't being collapsed when it could fit onto a single line (I'm not familiar enough to know if this part is a real bug, but it seemed weird). See MWE below.
$ python --version
Python 3.6.0
$ black --version
black, version 19.10b0
$ black --code $'run({\n 1: 2,\n})'
run(
{1: 2,}
)
$ black --code $'a = {\n 1:2,\n}'
a = {
1: 2,
}
$ black --code $'a = {\n 1:2\n}'
a = {1: 2}
I couldn't find this anywhere else, apologies if this is a duplicate. Possibly related #925 -- at least, the behavior seemed OK then, anyway.
This is a bug unfortunately. There are two acceptable behaviors for black:
run(
{
1: 2,
}
)
run(
{1: 2}
)
As mentioned in #1010, this triggers the E231 flake8 error.
Most helpful comment
As mentioned in #1010, this triggers the
E231flake8 error.