Is the damage psf/Black has done to the community reversible?
Python black formatting - ROS General - Open Robotics Discourse
visual studio code - Python black formatter for vscode not formatting - Stack Overflow
code formatting - In Python, how to tweak Black formatter, if possible? - Stack Overflow
Videos
» pip install black
I really don't understand why the Python Black formatter seems to be so popular. What is the point of a non-configurable and highly biased code formatter? I see no benefit in making all the code in the world look the same. They claim they are ending discussions about code formatting, but in reality they have sparked the biggest debate ever in the Python community with their subjective and often contradictory methods that have evolved over decades of established practices without the ability to configure the formatter. [1][2] The single/double quote disaster is just the most prominent example.
There are people out there who put readability above consistency with every other code base in the world that they will never come into contact with.
What bothers me most is the detachment of the Black developers, who dismiss all objections to their style choices as if they were opinions, and end every discussion by saying, you are just expressing an opinion and we prefer ours. But that is not true, there were many reasons, objectively measurable reasons, why this or that decision is better. Someone else might weigh these reasons differently and therefore come to a different conclusion. But the arguments used to enforce Black's decisions have never stood the test of time in a factual discussion.
I also notice that younger developers (< 35 years) are more likely to accept this approach than the more experienced ones.
[1] https://github.com/psf/black/issues/1252
[2] https://github.com/psf/black/issues/373
There are only a few settings you need to setup black as a formatter on VS Code. It seems you got most of it right, but I am doubtful about using relative paths for blackPath (VS Code should have shown an error if the path is indeed incorrect).
I suggest switching to absolute paths.
Here are my settings:
// User Settings
"editor.defaultFormatter": null,
"editor.formatOnSave": false, // enable per language
"[python]": {
"editor.formatOnSave": true
},
"python.formatting.provider": "black",
"python.formatting.blackPath": "/usr/local/bin/black"
// Workspace Settings
"python.formatting.blackPath": "/absolute/path/to/venv/with/black",
"python.formatting.blackArgs": [
"-l 120"
],
First of all, I suggest getting rid of the editor.defaultFormatter setting (or just set it back to the default null). Instead of setting a default for everything, configure your formatter for each language and for each extension. Here, it's null and then I configure python-specific settings then I have separate ones for other languages (ex. JS and C++). You mentioned something about Prettier, and that could be interfering with VS Code using black.
Second, make sure you are modifying the correct settings. VS Code has 3 sets of settings: User, Workspace, and Folder. I normally have the formatOnSave enabled for Python on the User settings, and provider set to black (using system-wide installed black). On a specific workspace, I have a virtual environment and I override the blackPath to the black specifically installed on that virtual environment. You can also just put all the settings in the User settings or use the same system-wide-installed black. But the main point here is to use absolute paths for both (basically copying the output of which black from the console).
Note that, if you specified blackPath to point to a particular virtual environment, make sure to select that same virtual environment on your workspace.
Lastly, you can check for any issues from the Output tab > Python:

I was also having the issue. What solved the issue for me was after downloading the Black formatter extension and once the document was open I did a right-click with the mouse and then press "format document". Choose black. I was good to go and had no more issues after that.
This is due to the default line length for black being longer than you'd like – 88 characters per line.
To decrease the line length, you can use the --line-length flag as documented here:
https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html
For example:
$ black --line-length 80 example.py
Black explains the --line-length setting in more detail here:
https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
Line length
You probably noticed the peculiar default line length. Black defaults to 88 characters per line, which happens to be 10% over 80. This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.
If you're paid by the line of code you write, you can pass
--line-lengthwith a lower number. Black will try to respect that. However, sometimes it won't be able to without breaking other rules. In those rare cases, auto-formatted code will exceed your allotted limit.You can also increase it, but remember that people with sight disabilities find it harder to work with line lengths exceeding 100 characters. It also adversely affects side-by-side diff review on typical screen resolutions. Long lines also make it harder to present code neatly in documentation or talk slides.
Emphasis on the final paragraph.
I'd recommend just keeping the default settings. The beauty of Black is that it chooses for you, and therefor preempts any arguments about which way is "best".
This is now possible by adding a trailing comma to your last argument.
In your example you would write instead:
def example_function(
arg_1: str,
arg_2: bool,
arg_3: int = 0,
arg_4: int = 1,
arg_5: float = 0.0, # <-- Notice the trailing comma
):