3 ms·
Doesn't Python have an autoformatting tool like gofmt or Prettier?
by growtofill 8y ago
Doesn't Python have an autoformatting tool like gofmt or Prettier?
- dhuramas 8y agoYapf- https://github.com/google/yapf https://github.com/google/yapf
- baq 8y agothere's autopep8 and a few other tools but none are considered idiomatic.
- eirki 8y agoBlack (The uncompromising Python code formatter) is all the rage atm. https://github.com/ambv/black https://github.com/ambv/black
- sametmax 8y agoYes. Most of the projects now use black https://github.com/ambv/black https://github.com/ambv/black
- quietbritishjim 8y agoThe problem that black had last time I saw it on hacker news is that it only inserts whitespace. Unlike braces-and-semicolon languages, that is sometimes not enough to format code well. For example, given the following line: x[1][4] = a[2] + b[4] Black will format like either of these: x[1][ 4] = a[2] + b[4] x[1][4] = a[ 2] + b[4] But not like either of these, unless you insert the brackets yourself: x[1][4] = ( a[2] + b[4]) x[1][4] = (a[2] + b[4]) Maybe this sounds like just one little problem but I think it's a fundamental flaw. I have seen the result of a Python formatter (not Black but had the same problem) applied to a couple of files and it's a total mess. I'd take inconsistent column widths over that any day. I asked the creator of black about it and he was pretty dismissive.
- Rotareti 8y agoI use yapf and in such cases backslashes work fine: x[1][4] =\ a[2] + b[4]