The docs for the Black Python code formatter say that the formatter "is not configurable". This is largely true, but if you have Black set up > to work in VSCode, you can configure the line length.

In VSCode, go 'Code -> Preferences -> Settings' and search for "python formatting black args".

Add two separate arguments, in this order: --line-length and n, where "n" is your desired number of allowed characters per line.

A few notes about line lengths in Python:

  • PEP8 recommends a line length of [79 characters]https://www.python.org/dev/peps/pep-0008/#maximum-line-length (72 for docstrings)
  • Black sets line lengths to 88 characters by default
  • The Django docs recommend a maximum line length of 119 characters (79 for docstrings)

If you are working on a shared project with a team, consider bypassing the VSCode settings entirely, and setting line lengths via the project's pyproject.toml:

[tool.black]
line-length = 119

Note to self, if you want to add it to the VS Code workspace settings, add this:

{
  "[python]": {
    "editor.defaultFormatter": "ms-python.black-formatter"
  },
  "black-formatter.args": ["--line-length", "119"]
}
continue reading on dev.to

⚠️ This post links to an external website. ⚠️