The issue is that you need =80 instead of 80 after --line-length for version 1.38.1 and above:

--line-length=80  

Answer from Pavel Hanpari on Stack Overflow
🌐
Read the Docs
black.readthedocs.io › en › stable › the_black_code_style › current_style.html
The Black code style - Black 26.3.0 documentation
See AST before and after formatting for more discussion. Black will add trailing commas to expressions that are split by comma where each element is on its own line. This includes function signatures. One exception to adding trailing commas is function signatures containing *, *args, or **kwargs.
🌐
Read the Docs
black.readthedocs.io › en › stable › usage_and_configuration › the_basics.html
The basics - Black 26.3.0 documentation
Example: black --line-ranges=1-10 --line-ranges=21-30 test.py will format lines from 1 to 10 and 21 to 30. This option is mainly for editor integrations, such as “Format Selection”. ... Due to #4052, --line-ranges might format extra lines outside of the ranges when there are unformatted lines with the exact formatted content next to the requested lines.
🌐
Visual Studio Code
code.visualstudio.com › docs › python › formatting
Formatting Python in VS Code
November 3, 2021 - Formatting makes source code easier to read by human beings. By enforcing particular rules and conventions such as line spacing, indents, and spacing around operators, the code becomes more visually organized and comprehensible.
🌐
PyPI
pypi.org › project › black
black · PyPI
fixed formatting of lambda expressions with default arguments (#468) fixed async for statements: Black no longer breaks them into separate lines (#372)
      » pip install black
    
Published   Mar 12, 2026
Version   26.3.1
🌐
GitHub
yellowduck.be › posts › vscode-setting-line-lengths-in-the-black-python-code-formatter
🔗 VSCode: Setting line lengths in the Black Python code formatter
Add two separate arguments, in this order: --line-length and n, where "n" is your desired number of allowed characters per line. ... PEP8 recommends a line length of [79 characters]https://www.python.org/dev/peps/pep-0008/#maximum-line-length ...
🌐
GitHub
github.com › psf › black
GitHub - psf/black: The uncompromising Python code formatter · GitHub
Pro-tip: If you're asking yourself "Do I need to configure anything?" the answer is "No". Black is all about sensible defaults. Applying those defaults will have your code in compliance with many other Black formatted projects.
Starred by 41.4K users
Forked by 2.7K users
Languages   Python
Top answer
1 of 7
111

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-length with 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".

2 of 7
72

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
):
Find elsewhere
🌐
GitHub
github.com › microsoft › vscode-black-formatter
GitHub - microsoft/vscode-black-formatter: Formatting support for Python using the Black formatter · GitHub
Note: Using this option may slowdown formatting. Examples: ["~/global_env/black"] ["conda", "run", "-n", "lint_env", "python", "-m", "black"] ... Path to a Python executable or a command that will be used to launch the Black server and any subprocess. Accepts an array of a single or multiple strings. When set to [], the extension will use the path to the selected Python interpreter. If passing a command, each argument should be provided as a separate string in the array.
Starred by 190 users
Forked by 45 users
Languages   Python 88.5% | TypeScript 11.1% | JavaScript 0.4%
🌐
GitHub
github.com › microsoft › vscode-black-formatter › discussions › 287
Black Settings · microsoft/vscode-black-formatter · Discussion #287
You can add "black-formatter.args": ["--line-length", "100"] to either your user settings or workspace settings.
Author   microsoft
🌐
GitHub
github.com › microsoft › vscode-black-formatter › issues › 251
`black-formatter.args` doesn't work · Issue #251 · microsoft/vscode-black-formatter
December 27, 2022 - // .vscode/settings.json { "black-formatter.args": ["--force-exclude", "AppData"] } files in AppData are still formatted on save because the args are not being sent to black: 2023-06-15 16:04:52.738 [info] c:\Users\user\AppData\Local\pypoetry\Cache\virtualenvs\project-zbC6VfKB-py3.11\Scripts\python.exe -m black --stdin-filename c:\Users\user\AppData\Local\Programs\Python\Lib\typing.py - 👍React with 👍1KotlinIsland ·
Author   DetachHead
🌐
Reddit
reddit.com › r/learnpython › code formatter (black) question
r/learnpython on Reddit: Code formatter (Black) question
August 23, 2023 -

Hey!

I'm curious how others handle the following situation or what is the "proper" way?
So I use Black as code formatter and it's awesome, but in certain situations also really annoying. I have written a script to convert video files (mp4, mkv, etc.) to avi (divx/xvid) because my toaster DVD player cannot play anything else on the USB port.
The script is not the problem, it works great but the issue is that I use subprocess to call ffmpeg. Subprocess wants the command line arguments as list elements and everyone who ever used ffmpeg via console knows that this program wants A LOT of arguments. And this is where the problem with Black comes in. I have to forward 26 arguments and all written in one line sum up to 248 characters. (I already use several vars, e.g. output file path, otherwise the line would be closer to 400 chars) Black is telling me that this is a bit long for one line and "fixes" this problem for me.
The result is that Black puts every single list element on its own line, many of the elements are only 2 to 4 characters long. This results in practically a whole empty page with some characters in the wild in the middle of my code. This is just as bad for readability as one very long line.

My question here is, how do you handle this situation? Do you …

  • obey the Black rules and let it put every element on a single line even this result in a empty page in middle of your code?

  • increase the line length to a very high number to get rid of the problem?

  • resort to multiple variables in which you put parts of the argument list and then concatenate the variables in the subprocess run function?

  • do you temporarily deactivate Black (you can put #fmt: off before and #fmt: on after the line to ignore) for that line of code to leave it long as it is?

  • any other solution?

Obviously Black planned for such a case, because it offers the option to exclude a code section from formatting. On the other hand, it doesn't automatically make use of it or offers this solution but rather line-break the list.

For the moment I have set my line-length to 500 because I don't share code, so it doesn't affect others.

🌐
DEV Community
dev.to › adamlombard › vscode-setting-line-lengths-in-the-black-python-code-formatter-1g62
VSCode: Setting line lengths in the Black Python code formatter - DEV Community
March 20, 2024 - I'm setting the arguments via pyproject.toml and had the problem, that the line-length was not reformatted properly. After a while, I found out that I have to restart the format server! ... Thank you!!! ... { "python.formatting.provider": "black", "python.formatting.blackArgs": ["--line-length", "120"], "python.linting.enabled": true }
🌐
LinkedIn
linkedin.com › pulse › automating-python-code-formatting-visual-studio-chris-mamon
Automating Python Code Formatting in Visual Studio Code
August 24, 2023 - "black-formatter.args": ["--line-length", "79"]: Specifies arguments for the Black formatter.
🌐
Safjan
safjan.com › home › note › change black line length
Change black line length
August 31, 2022 - in two separate lines provide the line length argument and it's value: ... In the second line, 100 is the desired limit for the maximum line length. You can add the information to the formatting section of settings.json which can be found in the project's .vscode directory · { "python.formatting.provider": "black", "python.formatting.blackArgs": ["--line-length", "120"], "python.linting.enabled": true }
🌐
YouTube
youtube.com › hey delphi
PYTHON : VS Code Python + Black formatter arguments - python.formatting.blackArgs - YouTube
PYTHON : VS Code Python + Black formatter arguments - python.formatting.blackArgsTo Access My Live Chat Page, On Google, Search for "hows tech developer conn...
Published   May 21, 2023
Views   37
🌐
Black
black.readthedocs.io
Black 26.3.0 documentation
This vastly improves the formatting of our code. Thanks a ton! ... [![Code style: black](https://img.shields.io/badge/code style-black-000000.svg)](https://github.com/psf/black)
🌐
DEV Community
dev.to › konstantinosblatsoukasrepo › vscode-black-formatter-4a0k
Vscode black formatter - DEV Community
March 22, 2024 - { "[python]": { "editor.defaultFormatter": "ms-python.black-formatter", }, "black-formatter.args": ["--line-length", "120"] } Subscribe · For further actions, you may consider blocking this person and/or reporting abuse · Konstantinos Blatsoukas ...