For more information about editing in Visual Studio Code, see Basic Editing and Code Navigation. The editor includes various features to help you be productive when writing code. Visual Studio Code is a powerful editing tool for Python source code. Configure IntelliSense for cross-compilingĮdit Editing Python in Visual Studio Code.YAPF seems like a strong contender.Ĭlearly, there are more formatters out there that I did not try. About autopep8, I am already using it, but it doesn’t make the code uniform so we are looking for a bigger weapon. As a team, we decided not to use it because it behaves in ways we disagreed with. Sad me though: If you look at the first code sample again, I cannot get YAPF to leave it alone either.Īs mentioned earlier, I started digging this topic after a colleague introduced us to Black. Since YAPF doesn’t provide anything similar, I have crafted a working bash command. I would have loved to see a flag like the -check from Black to validate the formatting. YAPF also has a “leave this section alone” functionality with # yapf: disable/enable. Configurations can be saved to a file that will be looked upon at launch. Again, the documentation fails to explain clearly what some of them do. On top of that, you can fine tweak your style of choice with “knobs”, as they call it. It comes with three built-in styles: pep8, google and chromium, but the documentation doesn’t bother highlighting the differences. One major difference: it can be configured. Like Black, it is what I would call a strict formatter. YAPF is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.
YAPF is made by google, but as the readme states: Maybe “Yet Another Python Formatter”? But that’s just a supposition. Because it only modifies code that is not pep8 compliant, it cannot be used as a way to stop having to manually manage uniformity of coding styles.īasically, autopep8 is great in helping with pep8 compliance and that’s it. If we take the two code samples above, in the Black section, they are both pep8 compliant so autopep8 would not change them. Its aim is fixing pep8 errors, not making the code uniform.
If you really insist on having it NOT touch some sections of code, you can surround them with # fmt: off/on. Black took it to another level: there is almost not even any discussions possible at the configuration level. One of the points for having a formatter is to make code uniform without having discussions around it. For this input:ĭata = īut that’s just me, and I get it. Personally, here is an example of formatting done by black that I dislike. If you are curious to learn why black formats the way it does, the readme contains a bunch of great rational explanations. There are in fact only two configurable formatting options: maximal line length and whether to normalize string quotes/prefixes or not. As the readme states it:īlack reformats entire files in place. Black is highly opinionated and has close to zero configuration. It will apply its style guide even where pep8 was not violated. First commit: Wed Mar 14 12:55:32 2018 -0700īlack is what I would call a strict formatter.No need to say, the contenders had to aim towards pep8 compliance. Following some discussions at work and the will of the team to adopt a python code formatter, I set out to explore some of them.