Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 707
Michael Hays Avatar asked Aug 27 '18 20:08

Michael Hays


People also ask

How do you set the maximum line length in VSCode?

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". A few notes about line lengths in Python: PEP8 recommends a line length of 79 characters (72 for docstrings)

How do you sort imports in VSCode?

You can run the extension using the shortcut Ctrl + Alt + O , or you can use the command palette Ctrl + Shift + P -> Dart: Sort Imports .

How do you organize imports in python?

Organize imports into groups: first standard library imports, then third-party imports, and finally local application or library imports. Order imports alphabetically within each group. Prefer absolute imports over relative imports. Avoid wildcard imports like from module import * .


1 Answers

There is a known bug with using Sort Imports on __init__.py files. Here is the full solution:

"python.sortImports.args": ["-ns", "__init__.py", "-l", "100"],
like image 65
Michael Hays Avatar answered Sep 20 '22 13:09

Michael Hays