[Python-projects] pylint: Differentiate between unused 'import X'and unused 'from X import *'

Maarten ter Huurne maarten.ter.huurne at philips.com
Thu Nov 30 18:07:02 CET 2006


Daniel Drake wrote on 2006-11-30 05:25:36 PM:

> I'm interested in pylint flagging unused imports in the form:
> 
>    import X
> 
> but, we have several places in the code where we do:
> 
>    from X import *
> 
> which often results in quite a few unused import warnings.
> 
> I'd like to be able to distinguish between the two. For now, I'd like to
> all ignore all warnings from the 2nd case, but be notified of the first
> one.

I agree that having separate message IDs for the two cases is an 
improvement.

However, I would recommend you not to use "*" imports at all, since they 
import everything, including:
- private (implementation) definitions
- the imports done by the module you are importing
Especially the latter is problematic, since it can lead to dependencies 
becoming invisible: your module might depend on more than just its direct 
imports, but you won't notice since those dependencies are made available 
indirectly. In C/C++ this is problem and it is unavoidable because of the 
#include mechanism, but in Python it can be avoided. PyLint even has a 
dedicated message which warns about wildcard imports (W0401).

Bye,
                Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.logilab.org/pipermail/python-projects/attachments/20061130/3a21abdc/attachment.html 


More information about the Python-Projects mailing list