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

Feature request: Imports on a new line #1097

Closed
Ran4 opened this issue Mar 27, 2021 · 3 comments
Closed

Feature request: Imports on a new line #1097

Ran4 opened this issue Mar 27, 2021 · 3 comments
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@Ran4
Copy link

Ran4 commented Mar 27, 2021

If we have this code, where the cursor it at |:

from uuid import (
    UUID,
)

uuid4|

and choose to auto-import uuid4 from uuid, then I end up with

from uuid import (
    UUID, uuid4,
)

uuid4|

Describe the solution you'd like

In order to generate more readable git diffs, I much prefer this behaviour:

from uuid import (
    UUID,
    uuid4,
)

uuid4|

It would be really cool if there was a way of customizing this behaviour.

@Ran4 Ran4 changed the title Imports on a new line Feature request: Imports on a new line Mar 27, 2021
@erictraut
Copy link
Contributor

Thanks for the suggestion.

Since this isn't a core type checking feature and is instead a language server feature, I'm going to transfer it to the pylance repo where it will receive attention and discussion.

We tend to try to avoid adding new settings if we can help it. I think we could avoid making this configurable by adding more smarts to the auto-insert logic. If the import is already using a multi-line format, we should probably honor that.

@erictraut erictraut transferred this issue from microsoft/pyright Mar 27, 2021
@erictraut
Copy link
Contributor

I've added a new heuristic so the auto-import text honors the existing formatting.

from uuid import UUID

becomes

from uuid import UUID, uuid4

and

from uuid import (
    UUID,
)

becomes

from uuid import (
    UUID,
    uuid4,
)

This avoids the need for an explicit setting.

This change will be in the next release of pylance.

@erictraut erictraut added enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Mar 29, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.4, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202134-31-march-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants