News for hackers. Stuff that matters.
Re:Format Python Code Using YAPF by scrollaway on Sunday February 09, 2020 @05:12AM (#22281359)
Black is just slightly too opinionated. It gives you configuration options for benign things such as numeric separators, but it flat out refuses to allow tab indent, which a fairly significant part of the python community uses.

I tried to PR a --use-tabs flag but the PR was rejected without comments. Had to fork Black to be able to use it. Tan is a drop-in replacement that allows --use-tabs (and use-tabs = true in pyproject.toml).

https://github.com/jleclanche/tan

Re:Format Python Code Using YAPF by stubish on Sunday February 09, 2020 @05:51AM (#22281485)
The reason Black is fast becoming standard is precisely because it is so opinionated. Like the other code formatters that have successfully become 'normal', such as gofmt. An option means that there isn't a standard, but several standards. And the people pushing Black in their projects see the benefit of a global standard, even though it is rarely 100% their personal preferences. It is a consensus.
Re:Format Python Code Using YAPF by scrollaway on Sunday February 09, 2020 @07:44AM (#22281820)
Prettier is more widespread than black, is very opinionated, and still has an option for tab indent. This is a strawman.
Re:Format Python Code Using YAPF by weberc2 on Sunday February 09, 2020 @09:23AM (#22282222)
How is this argument a strawman?
Re:Format Python Code Using YAPF by stubish on Sunday February 09, 2020 @10:22PM (#22286195)
Prettier's opinion then is that tabs are irrelevant to the formatting. Which is probably fine for the all the languages Prettier seems to support. Unlike Python, where tabs vs spaces matter. Mixing tabs and spaces is a problem, and a formatter cannot automatically support both or risks changing the meaning of code.
Re:Format Python Code Using YAPF by scrollaway on Tuesday February 11, 2020 @09:09AM (#22298561)
I don't know how you arrive to this conclusion… prettier never mixes tabs and spaces, it would be a bug if it did. And there's no meaningful difference between tabs and spaces in Python either. Python has significant indent stops, that's all.

Furthermore, prettier has a python plugin which does support tabs.

Re:Format Python Code Using YAPF by jakear on Sunday February 09, 2020 @05:23AM (#22281388)
Thats a shame, especially as I've heard tabs are more accessible: https://www.reddit.com/r/javascript/comments/c8drjo/nobody_t...
Re:Format Python Code Using YAPF by scrollaway on Sunday February 09, 2020 @05:27AM (#22281400)
Precisely why I use them and why I'm uncomfortable with Black refusing to add the option (https://github.com/psf/black/pull/513).
Re:Format Python Code Using YAPF by patrec on Sunday February 09, 2020 @07:53AM (#22281852)
This argument sounds quite bizarre to me. Why would a visually impaired programer not manage to set their editor up to show indenting spaces the way they want, or failing that, collaborate with others to do so?

It's not like they can be effective at their job either without the ability to read 3rd party code, which overwhelmingly will be space indented.

Re:Format Python Code Using YAPF by j88439h84 on Sunday February 09, 2020 @01:21PM (#22283462)
How to set an editor to use big visual indents for spaces?
Re:Format Python Code Using YAPF by patrec on Sunday February 09, 2020 @04:06PM (#22284305)
Depends on the editor, of course, but e.g.

https://www.emacswiki.org/emacs/redshift-indent.el

(Haven't tried the above, but I've done fairly extensive display hacks with emacs in the distant past, so I have a fair amount of confidence that it's not hard).

Re:Format Python Code Using YAPF by zelly on Sunday February 09, 2020 @02:09PM (#22283734)
While I prefer tabs whenever I can, I can see why it doesn't support it. If you have to share code, you're going to use spaces. For some reason everyone including Guido insists on spaces. I would rather not have to waste time thinking about formatting or much less which formatting style to use. New languages like Go and Rust solved this problem.