On Sun, Nov 14, 2021, at 09:13, Charles R Harris wrote:
The black formatter is much improved in its latest version and I think good enough to start using. The main drawbacks that I see are:
- all operators, including '*' and '/', get spaces around them,
- very long strings are not broken into multiple lines,
- lists, tuples, and function signatures are either on one line, or broken into multiple lines of one element/argument each,
- the formatting of extended logical expressions could be improved to emphasize the priority of 'and' over 'or' operators
I tried yapf recently, and was pleased with the output. One concern about yapf was that it has many configuration options: but the only important thing is that you fix the knobs, then you simply have a different version of black.
In my experience, while none of these tools are perfect, not having to have discussions around formatting is completely worth it!
+1 on everything Stéfan said. I never liked black’s formatting, but I have *absolutely* appreciated having zero discussions/push commits/code suggestions to deal with formatting in napari. I have since added yapf to my own repos with a config I like *and* added yapf auto-formatting-on-save to my VSCode, and I don’t even have to have formatting discussions with *myself* anymore. 😂 It’s very liberating!
For reference, here’s my yapf config:
As Stéfan said, fix the knobs (yours might be different), then forget about it!
Oh, and yes, yapf does allow formatting only the diff. I agree that reformatting the entire code base is problematic.