I'm using the May 2018 Python extension (released June 2018) for VS Code 1.23.1 on Windows, python 3.6 via Anaconda, conda installing black from conda-forge into my conda environment.
In my user settings.json I have the below:
"python.formatting.blackArgs": [ "--line-length 80" ],
which I'd think would be the correct way to structure this to pass arguments to black in VS Code Python formatting.
However, in my python Output pane I get the below:
Formatting with black failed. Error: Error: no such option: --line-length 80
EDIT: If I edit my settings.json to be no args, such as:
"python.formatting.blackArgs": [],
black works as expected.
Does anyone know how to pass arguments correctly to the new (as of June 2018) black formatter?
A Visual Studio Code extension with support for the black formatter. The extension ships with black=22.6.0. This extension is supported for all actively supported versions of the python language (i.e., python >= 3.7). The bundled black is only used if there is no installed version of black found in the selected python environment.
This extension is experimental. The plan is that it will eventually replace the black formatting functionality of the Python extension. Once installed in Visual Studio Code, "Black Formatter" will be available as a formatter for python files. Please select "Black Formatter" (extension id: ms-python.black-formatter) as the default formatter.
Install Microsoft's Python extension in VSCode: Open your VSCode settings, by going 'Code -> Preferences -> Settings'. Search for "python formatting provider" and select "black" from the dropdown menu: In the settings, search for "format on save" and enable the "Editor: Format on Save" option: Black will now format your code whenever you save ...
Black is "the uncompromising Python code formatter." It can be configured to automatically format your code whenever you save a file in VSCode. Install Black in your virtual environment: Open your VSCode settings, by going 'Code -> Preferences -> Settings'. Search for "python formatting provider" and select "black" from the dropdown menu:
The issue is that you need =80
instead of 80
after --line-length
for version 1.38.1 and above:
--line-length=80
The examples of formatter-specific settings show the following:
"python.formatting.autopep8Args": ["--max-line-length", "120", "--experimental"], "python.formatting.yapfArgs": ["--style", "{based_on_style: chromium, indent_width: 20}"]
So try:
"python.formatting.blackArgs": ["--line-length", "80"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With