Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

isort config to always have multiple imports in parenthesis

Tags:

python

isort

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,
)
like image 253
gustavz Avatar asked Jan 19 '26 17:01

gustavz


1 Answers

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
)
like image 162
persinac Avatar answered Jan 22 '26 05:01

persinac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!