Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isort 5 splits "as" imports onto new lines #1305

Closed
Zac-HD opened this issue Jul 9, 2020 · 4 comments
Closed

isort 5 splits "as" imports onto new lines #1305

Zac-HD opened this issue Jul 9, 2020 · 4 comments
Labels
accepted_next_major Accepted for next major release documentation Improvements or additions to documentation question Further information is requested

Comments

@Zac-HD
Copy link
Member

Zac-HD commented Jul 9, 2020

One line I end up writing in a lot of scripts is

from hypothesis import given, strategies as st

and both black and isort 4 are happy with this. However, isort 5 prefers to split it onto multiple lines:

from hypothesis import given
from hypothesis import strategies as st

which I don't like so much, but 🤷‍♂️. However, if you have a longer list of imported names or turn down the line length, it looks really weird indeed:

from hypothesis import (
    given,
)                            # I did not expect these two lines to exist,
from hypothesis import (     # but they even come back if I delete them!
    strategies as st,
)

Maybe there's just a setting that I (or isort) could add to --profile=black, because the first form is definitely my favorite.

@timothycrosley
Copy link
Member

Hi @Zac-HD,

I agree the first form looks nicer! The configuration option to add to have that style is combine_as_imports. See: https://timothycrosley.github.io/isort/docs/configuration/options/#combine-as-imports. It also works nicely with the black profile, and I'll keep this in mind for that profile in the future. In case it's helpful, you can also try out different combinations of settings online now, here: https://timothycrosley.github.io/isort/docs/quick_start/0.-try.

Thanks!

~Timothy

@timothycrosley timothycrosley added documentation Improvements or additions to documentation question Further information is requested labels Jul 9, 2020
@jdufresne
Copy link
Collaborator

WDYT about making combine_as_imports as default True? This behavior surprised me as well and I think most projects prefer these import as one line. By flipping the default, we'd require less configuration in default cases.

@abitrolly
Copy link

abitrolly commented Sep 20, 2021

@jdufresne I've got the same question #1812

@timothycrosley timothycrosley added the accepted_next_major Accepted for next major release label Sep 24, 2021
@timothycrosley
Copy link
Member

Just a heads up! It might be a bit of time before the next major release of isort is finished, but once that happens the default will be switched to this. It hasn't been switched earlier just because of isort's formatting guarantee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted_next_major Accepted for next major release documentation Improvements or additions to documentation question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants