[code-quality] How to support third-party python package

Ian Cordasco graffatcolmingov at gmail.com
Mon Feb 23 15:50:45 CET 2015


On Mon, Feb 23, 2015 at 12:59 AM, DevOps <david.malan at aol.com.dmarc.invalid>
wrote:

> Swampy is third-party python package through pip installed, but flake8
> don’t detect it.
>
>
> --
> Sent with Airmail
>

Hi "DevOps",

Your question made little sense without a great deal of context, so I went
off in search of context and found
https://github.com/scrooloose/syntastic/issues/1333 and
https://github.com/klen/pylama/issues/29 and I understand what you're
asking now. In the future, please don't make myself or anyone else go
through the trouble of determining your question when you could include all
of the details in your first post.

The problem isn't that flake8 (or more accurately, pyflakes) cannot detect
swampy, it's that by importing *, pyflakes through purely static analysis
will not be able to tell you when you have unused imports because the
symbols imported are not in the text. PyFlakes will not introspect anything
on your python path to determine symbols used or anything else like that
because that could become computationally expensive. If you want PyFlakes
to stop issuing this warning, you should do

    from swampy.TurtleWorld import thefunction, theotherfunction,
ThisClass, ThatOtherClass

Depending on what you need from it. Alternatively, just import the
submodule like

    from swampy import TurtleWorld

And use qualified references to the functions/classes that are inside it.

There is no bug with flake8 (or pyflakes). At best, the wording could be
made easier for developers whose first language is not English. At worst,
you should look into the myriad of style guides for Python that tell you
not to use wildcard imports (like Google's
https://code.google.com/p/soc/wiki/PythonStyleGuide#Python_Language_Rules
or PEP8 https://www.python.org/dev/peps/pep-0008/#imports).

Cheers,
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/code-quality/attachments/20150223/9021204a/attachment.html>


More information about the code-quality mailing list