Black 19.10b0 no longer fixes short argument lists to a single line
See original GitHub issueDescribe the bug
In previous versions of Black, short argument lists would be wrapped to a single line. In new versions of Black, this is not always the case.
If the argument list starts off as a single line, it’ll remain a single line. If the argument list starts as multiple lines, it’ll remain multiple lines. See test case below.
To Reproduce
test.py
my_func(
"a",
"b",
)
With Black 19.3b0
@@ -1,5 +1,2 @@
-my_func(
- "a",
- "b",
-)
+my_func("a", "b")
With Black 19.10b0
@@ -1,5 +1,4 @@
my_func(
- "a",
- "b",
+ "a", "b",
)
Expected behavior
I expect the behavior experienced in 19.3b0.
Environment
- Version: 19.10b0 (also master)
- OS and Python version: Fedora 30 Python 3.7.5
Does this bug also happen on master?
Yes.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:8 (7 by maintainers)
Top Results From Across the Web
black 19.10b0 - PyPI
use a single blank line between top-level class definitions, or none if the classes are very small. Black enforces the above rules. There...
Read more >Formatter black is not working on my VSCode...but why?
Just run from the command line if you need to format a lot of files at once. First, check if you have this...
Read more >ChangeLog - babeltrace - Gitiles - Code Review - LTTng
Fix : output non-LTTng CTF trace with same relative path as input. * cli: don't include version.h in babeltrace2-cfg-cli-params-arg.c.
Read more >How to format files on save using black with neovim and coc
Something unusual that does happen is that my buffer for a python file is constantly in need of saving. By which I mean...
Read more >Contributing to pandas — pandas 1.1.3 documentation
To the new user, working with Git is one of the more daunting aspects of ... You should use a black version >=...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
FWIW, as an end user, I find this new beahvior quite suprising and a move away from the opinionated philosophy I really love about Black. When I write Python code, I almost never think about formatting anymore because I know Black will take of it later. With this change, it means I’m back to thinking about formatting. “Should I add a trailing comma or remove it?”, is now a question I’ll be asking before submitting code.
I normally blindly add a trailing comma to all code. Not because I want to keep arguments across multiple lines, but just out of habit. I don’t think about it much more than that and let Black figure it out later.
The PR that introduce this change is all about preserving multiple lines in collections. So what does that have to do with argument lists of function calls? Are you intentionally grouping argument lists in with collections here, or is that an unintended side effect of the implementation?
I think there is another problem with this change. Consider a very long argument list:
After formatting using master, this becomes (notice a trailing comma was added):
Now – perhaps due to refactoring – the last 2 arguments are removed and reformatted:
Now, because of this new change and the added trailing comma, Black doesn’t reformat the line back to a single line.
This is intended behavior of the magic trailing comma. As of recent releases, you can use
--skip-magic-trailing-comma
if you don’t want this behavior.