unimport icon indicating copy to clipboard operation
unimport copied to clipboard

Multiple star imports with clashing names

Open isik-kaplan opened this issue 5 years ago • 4 comments
trafficstars

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.

isik-kaplan avatar Sep 29 '20 13:09 isik-kaplan

You can use alias to the same name imports like from collections import defaultdict as coll_dd from _collections import defaultdict as _coll_dd

shivam-S-bisht avatar Oct 01 '20 04:10 shivam-S-bisht

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.

isik-kaplan avatar Dec 02 '20 12:12 isik-kaplan

In the light of #150 my previous suggestion is no longer(maybe wasn't ever) plausible. So, scratch that.

isik-kaplan avatar Dec 07 '20 15:12 isik-kaplan

This is a bug and needs to be solved without giving the user a choice and avoid running it twice for performance reasons.

hakancelikdev avatar Dec 07 '20 15:12 hakancelikdev