Would it be possible to delete unused import?
Hi! if nobody is already working on this, I would like to give it a shot. I'm still in the process of going through the codebase and afterwards will be able, hopefully to come up with some way to get it done.
Just as a note - flake8 already gives a warning about unused imports, so maybe it is not necessary to also include it in this package. In the spirit of do one thing and do it well.
@jugmac00 thanks. I think the issue is to remove the unused imports, which could be a nice little addition to isort especially in module(s) with a large number of imports.
@anirudnits I just applied Flake8 (F401 Module imported but unused) to a large legacy code base - and yes, it was a bit of work to delete all unused imports by hand, but even Flake8 marked one import as unused although it was used.
I would not feel well with isort removing imports.
This is only my personal opinion. When unused imports get deleted automatically in future, I just can hope my test suite is good enough to find all false positives.
Update
My test suite caught two more false positives from Flake8
@jugmac00 that's a valid concern and I do understand why this feature will negatively impact isort.
I'm perfectly happy with isort doing this, as long as it requires a CLI flag, and can't be made the default via a config file. isort itself would break if its own "unused" imports were removed. But yeah, I can only see havoc happening if this could be put in a config, and happened automatically to everyone using precommit.
Would it be possible to delete unused import?
What this would mean in any decent editor with automatic input sorting: you comment out the last line the requires an import, you save the file -> the import is gone. You uncomment the same line, you save the file -> the import does not come back, you are left with non-working code. That goes way beyond what I would expect i*sort* to do.
This definitely needs a default-off flag. Or maybe do this in a separate iclean binary?
I really like the idea of a separate command to do it. Especially, since unlike isort itself, it would likely utilize flake8 or a different external library to identify the unused imports as others have already solved that problem well - isort's job would just be to make sure the format doesn't change during / after the removal.
Hi all, I've just created autoimport for this purpose. Issues and pull requests are welcome :)
Most helpful comment
I really like the idea of a separate command to do it. Especially, since unlike isort itself, it would likely utilize flake8 or a different external library to identify the unused imports as others have already solved that problem well - isort's job would just be to make sure the format doesn't change during / after the removal.