How to configure line length for VS Code python Sort Imports in user settings?

Question:

I’m using the Sort Imports function of the Python extension for VS Code. I’d like to configure the line length for this to 100; however, I’ve been unable to properly set this in my settings.json file. From the documentation, it seems like "python.sortImports.args": ["-l", "100"] should work, but it’s giving me an error: Invalid patch string: Skipped 1 files.

Any ideas?

Asked By: Michael Hays

||

Answers:

There is a known bug with using Sort Imports on __init__.py files. Here is the full solution to put in vscode’s .vscode/settings.json:

"python.sortImports.args": ["-ns", "__init__.py", "-l", "100"],
Answered By: Michael Hays

Nowdays, it’s adding:

    "isort.args": ["-l", "100"],

to your settings file.

Answered By: felix