unimport
unimport copied to clipboard
Multiple star imports with clashing names
from _collections import *
from collections import *
print(defaultdict)
Unimport works fine when it comes to finding the correct import module for the variables, but this doesn't help when it comes to clashing names.
The problem can be avoided by running unimport twice with the -r flag, allowing it to turn the above into
from _collections import defaultdict
from collections import defaultdict
and then running again to remove the first unused import, but I think it should be able to do it in a single run without needing to run in twice.
You can use alias to the same name imports like
from collections import defaultdict as coll_dd
from _collections import defaultdict as _coll_dd
Since we can simply "fix" the end-users' issue by running unimport twice should we maybe simply run it twice? Maybe with something like --fix-star-collisions. Sometimes the best solution is the easiest solution.
In the light of #150 my previous suggestion is no longer(maybe wasn't ever) plausible. So, scratch that.
This is a bug and needs to be solved without giving the user a choice and avoid running it twice for performance reasons.