How to avoid PEP8 'imported but unused'

Fábio Santos fabiosantosart at gmail.com
Sun May 5 12:18:40 EDT 2013


I usually do this on pyflakes:

import whatever
assert whatever  # silence pyflakes

Pyflakes and pep8 have no way of knowing django will import and use your
module, or whether you are just importing a module for the side effects, so
they issue a warning anyway. Assert'ing counts as using the module, so it
counts as an used import.

On 5 May 2013 17:05, "Adam Jiang" <jiang.adam at gmail.com> wrote:
>
> I am new to python. Now, I am woring on an application within Django
> framework. When I checked my code with pep8 and pyflakes, some warning
> messages show up-'Foobar imported but unused'. Obviously, it indicates
> that some modules are imprted to current module but never get
> references. However, it seems the message is wrong in this case:
>
> # file: urls.py
> urlpattens = patterns(
>     '',
>     url('^signup/$', 'signup')
> }
>
> # file: register.py
> def signup(request):
>     return ...
>
> # file: views.py
> import signup from register
>
> The warning message is shown in file views.py. It seems to me that the
> code is okay because Django requires all functions serve as 'view' is
> typically go into views.py. 'import' is about get 'signup' function
> into module 'views.py'. Or, I am totally wrong? Is there a proper way
> to avoid this warnning?
>
> Best regards,
> /Adam
> --
> http://mail.python.org/mailman/listinfo/python-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130505/fa33e16d/attachment.html>


More information about the Python-list mailing list