Unexpected trailing comma left when wrapping up the list parameter inside a function call
See original GitHub issueDescribe the bug Unexpected trailing comma left when wrapping up the list parameter inside a function call.
To Reproduce
Run black on the following snippet:
foo(
[
"list",
"of",
"values",
]
)
It results in the following output:
foo(
["list", "of", "values",]
)
So it left the trailing comma at the end of the list.
Expected behavior According to the docs regarding trailing commas - “Unnecessary trailing commas are removed if an expression fits in one line” and yet there is trailing comma left at the end. Or maybe I misunderstood the docs?
This wouldn’t bug me a lot except for the fact that it triggers a pep8 checker to point it out (pep8 explicitly discourages this behavior here. And since black is strict subset of PEP 8
, that should be taken into account, right?
Environment:
- Version:
lack, version 19.10b0
- OS and Python version: MacOS/Python 3.7.5
Does this bug also happen on master? Yep, checked with https://black.now.sh/?version=master
Additional context Thanks for providing awesome formatter! 😄 I’d be willing to help fixing that (if you consider that a bug) if someone could point me into the right direction
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:5 (3 by maintainers)
Top GitHub Comments
Resolved by #1288 which make the “magic trailing comma” feature generally usable in almost all situations. Now nested trailing commas (and I guess Black thought function parameters/arguments count as nested too) will actually make Black explode the collections.
This fix is available in the latest version,
20.8b1
. If you the reader are confused by what the “magic trailing comma” feature is, please read the documentation on it.Environment:
20.8b1
CPython 3.8.5
Ubuntu 20.04.01 LTS
Fixed in PR