DEV Community

loading...

Discussion on: Python beyond PEP8

Collapse
rhymes profile image
rhymes

Yeah, PEP8 is a little limited. Fortunately there are automated ways to go beyond that.

My favorite tool is black. I think it's better than the pep8 formatter (which as you highlighted is limited) and yapf (which is sometimes weird).

You can integrate it with pretty much any tool (editor, CI, git hooks...) and forget about most of those issues. Give it a try!

Collapse
thiefmaster profile image
Adrian

Worst disadvantage of black? It forces double quotes on you unless you disable quote management altogether.

Collapse
rhymes profile image
rhymes

Surrender to the robots :-)

Prettier for JS defaults to double quotes
Rubocop for Ruby defaults to double quotes
black for Python defaults to double quotes and gives a good reason for it:

The main reason to standardize on a single form of quotes is aesthetics. Having one kind of quotes everywhere reduces reader distraction. It will also enable a future version of Black to merge consecutive string literals that ended up on the same line (see #26 for details).

Why settle on double quotes? They anticipate apostrophes in English text. They match the docstring standard described in PEP 257. An empty string in double quotes ("") is impossible to confuse with a one double-quote regardless of fonts and syntax highlighting used. On top of this, double quotes for strings are consistent with C which Python interacts a lot with.

Thread Thread
claytron profile image
Clayton Parker

Rubocop defaults to single quotes because double quotes do more escaping and interpolation.

docs.rubocop.org/en/latest/cops_st...

Thread Thread
rhymes profile image
rhymes

Thanks Clayton, I remembered it wrongly!

Collapse
edelvalle profile image
Eddy Ernesto del Valle Pino Author

I didn't know... Will take a look into it.. even if it enforces double quotes... hahahaha

Forem Open with the Forem app