简体   繁体   中英

How to make isort always produce multi-line output when there are multiple imports on a line?

I'm currently using isort --profile=black --line-length=79 as a linter in my project for python files.

This produces the Vertical Hanging Indent (mode 3 in isort's documentation kind of output:

from third_party import (
    lib1,
    lib2,
    lib3,
    lib4,
)

This multiline mode only applies if the line is longer than 79 characters, though. Is there a mode that cause a multiline output as soon as there are two or more imports on the same line, no matter how long the line is?

I tried hacking it with isort -m=3 --trailing-comma --line-length=1 , but shorter line length will cause multiline output even when there is a single import, which I don't want:

from third_party import (
    lib1,
)

You should use the --force-grid-wrap 2 flag in the CLI or set in the settings file like pyproject.toml option force_grid_wrap = 2 . This would force isort to produce multiline output for 2 or more imports, regardless of line length. More info about this option

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM