VS Code Python + Black formatter arguments – python.formatting.blackArgs
Question:
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?
Answers:
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"]
My setting is:
"python.formatting.blackArgs": ["--line-length=110"]
and it’s working correctly.
The equal sign was missing in your user settings.json
The proper way to config in the Settings GUI pane is with --line-length
and the desired value as separate items:
Visual Studio Code GUI Settings for Python Formatting
This converts into the settings.json into this:
Visual Studio Code JSON Settings for Python Formatting
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length", "110"]
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?
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"]
My setting is:
"python.formatting.blackArgs": ["--line-length=110"]
and it’s working correctly.
The equal sign was missing in your user settings.json
The proper way to config in the Settings GUI pane is with --line-length
and the desired value as separate items:
Visual Studio Code GUI Settings for Python Formatting
This converts into the settings.json into this:
Visual Studio Code JSON Settings for Python Formatting
"python.formatting.provider": "black",
"python.formatting.blackArgs": ["--line-length", "110"]