isort config to always have multiple imports in parenthesis

1k views Asked by At

I am looking for an isort config to have one line per import if it's a single import but as soon as you have multiple imports it switches to parenthesis, so it would look like the following

from something import one_thing
from another.thing import (
    uno,
    due,
    tres,
)
1

There are 1 answers

0
persinac On BEST ANSWER

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

See the first comment.

Use force_grid_wrap = X where X is the threshold of imports before wrapping them. Note, you should still use the multi_line_output option to set how you want the wrapped imports to actually look like.

For example:

multi_line_output = 3
force_grid_wrap = 2

Turns this:

from connector import conn
from logger import log
from exceptions import EmptyFieldException, MissingBodyException

Into this:

from connector import conn
from logger import log
from exceptions import (
    EmptyFieldException,
    MissingBodyException
)