Isort: multi line not working if imports contain aliases

Created on 24 Jan 2020  路  1Comment  路  Source: PyCQA/isort

I have a import statement:

from review.domains.services import (
    CompanyAPI as CompanyAPIService,
    CompanyClientException,
    Review as ReviewService,
    Job as JobService,
    JobGetException,
    Qualifications,
)

isort is changing this to:

from review.domains.services import CompanyAPI as CompanyAPIService
from review.domains.services import CompanyClientException
from review.domains.services import Job as JobService
from review.domains.services import JobGetException, Qualifications
from review.domains.services import Review as ReviewService

my isort config is the following:

'include_trailing_comma': 1,
'multi_line_output': 3,
'line_length': 99

I would like to keep it as one import statement rather then several. It seems like the reason is the use of aliases as. It's working as expected if I remove the alias definitions.

documentation question

Most helpful comment

Hi @matthias-mess,

I can understand the confusion here! By default, isort puts as imports on their own line, as they are seen as exceptional, and not intended for broad use, but more for as-needed aliasing - in particular to help with refactoring. In the case where they are widely used, and you want to have them mixed isort has the --combine-as CLI flag or combine_as_imports config setting to provide the behaviour that you seek.

Thanks!

~Timothy

>All comments

Hi @matthias-mess,

I can understand the confusion here! By default, isort puts as imports on their own line, as they are seen as exceptional, and not intended for broad use, but more for as-needed aliasing - in particular to help with refactoring. In the case where they are widely used, and you want to have them mixed isort has the --combine-as CLI flag or combine_as_imports config setting to provide the behaviour that you seek.

Thanks!

~Timothy

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jack1142 picture jack1142  路  3Comments

ionelmc picture ionelmc  路  3Comments

cjerdonek picture cjerdonek  路  3Comments

peteboothroyd picture peteboothroyd  路  3Comments

ionelmc picture ionelmc  路  3Comments