PyCQA / isort

A Python utility / library to sort imports.
https://pycqa.github.io/isort/
MIT License
6.49k stars 580 forks source link

isort Deletes a used import #2005

Open mangelozzi opened 1 year ago

mangelozzi commented 1 year ago

I tried to test it with the try online tool but it just freezes on "loading".

Heres the code before isort:

from django.core.management.base import BaseCommand

from lib import buildlib
from ...import build

class Command(BaseCommand):

    def handle(self, *args, **options):
        options = buildlib.Options(verbose=True, force=True, prefix="WcApp")
        build.build_all_wc(options)

After isort, it removes the build import:

from django.core.management.base import BaseCommand
from lib import buildlib

class Command(BaseCommand):
    def handle(self, *args, **options):
        options = buildlib.Options(verbose=True, force=True, prefix="WcApp")
        build.build_all_wc(options)

I tried:

from ... import build as build_

But it still gets removed

kaste commented 1 year ago

I can actually reproduce with the first snippet but not with the last one.

T.i.

from ...import build
from ...import build as build_

both get removed, but with an added space:

from ... import build
from ... import build as build_

they stay intact.