python-guide icon indicating copy to clipboard operation
python-guide copied to clipboard

Recommended autoformatters?

Open cxong opened this issue 7 years ago • 5 comments

In the Code Style document https://github.com/realpython/python-guide/blob/master/docs/writing/style.rst there's a small mention of autopep8 which can be used to format code to meet PEP8 standards. But there's at least two other autoformatters (black and yapf) which are as good if not better. There's a blog comparing the three here: https://medium.com/3yourmind/auto-formatters-for-python-8925065f9505 The gist of it is: autopep8 is the most conservative, black is the most opinionated, and yapf is somewhere in between depending on how you configure it.

Should the python guide have an opinion on which auto formatters should be used? In addition to the current mention of autopep8. I think it would be good to expand this section; auto formatters are quite useful and of great interest to developers coming from tools like gofmt and prettier.

cxong avatar Oct 30 '18 02:10 cxong

@cxong Agreed, would be great to expand this section. Personally I'm a big fan of black, I think it's awesome. If you want to put together a pull-request that expands the section that'd be fantastic!

dbader avatar Oct 30 '18 02:10 dbader

I've only used black a little, so I don't think I have enough experience to author this section. Happy for someone else to take it up in the meantime.

cxong avatar Nov 01 '18 01:11 cxong

@dbader I'm thinking about adding a PR for this. Do you think this is still relevant? I'd add a sub section about auto-formatting giving brief instructions on how to install and use autopep8, yapf, and black.

schilli91 avatar Oct 08 '20 21:10 schilli91

@schilli91 Yes I think that'd be beautiful!

dbader avatar Oct 08 '20 21:10 dbader

@dbader I just opened the PR #1081. I'm happy to receive some feedback.

schilli91 avatar Oct 11 '20 10:10 schilli91