Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #44754 > unrolled thread

Re: How to avoid PEP8 'imported but unused'

Started byAdam Jiang <jiang.adam@gmail.com>
First post2013-05-06 01:40 +0900
Last post2013-05-06 01:40 +0900
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to avoid PEP8 'imported but unused' Adam Jiang <jiang.adam@gmail.com> - 2013-05-06 01:40 +0900

#44754 — Re: How to avoid PEP8 'imported but unused'

FromAdam Jiang <jiang.adam@gmail.com>
Date2013-05-06 01:40 +0900
SubjectRe: How to avoid PEP8 'imported but unused'
Message-ID<mailman.1299.1367772046.3114.python-list@python.org>
Thanks. It works very well.

One more question. In this particular case it seems 'assert' should be
safe as a workaround, doesn't it?  'assert' will check if the symbol
is imported and not NULL. Is there side effect if I just applied this
rule as a generic one.

/Adam
On Sun, May 05, 2013 at 05:18:40PM +0100, Fábio Santos wrote:
> 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@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
> 

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web