Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!eweka.nl!hq-usenetpeers.eweka.nl!xlned.com!feeder1.xlned.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'anyway.': 0.05; 'importing': 0.05; "'',": 0.07; 'framework.': 0.09; 'imported': 0.09; 'indicates': 0.09; 'okay': 0.09; 'references.': 0.09; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'django': 0.11; 'def': 0.12; 'obviously,': 0.16; 'pep8': 0.16; 'silence': 0.16; 'urls.py': 0.16; 'wrote:': 0.18; 'module': 0.19; 'seems': 0.21; 'import': 0.22; 'email addr:gmail.com>': 0.22; 'cc:addr:python.org': 0.22; 'module,': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; '>': 0.26; 'shown': 0.26; 'header :In-Reply-To:1': 0.27; 'function': 0.29; 'message- id:@mail.gmail.com': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'serve': 0.31; 'usually': 0.31; 'assert': 0.31; 'file:': 0.31; 'file': 0.32; 'checked': 0.32; 'url:python': 0.33; 'totally': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'wrong': 0.37; 'application': 0.37; 'whatever': 0.38; 'issue': 0.38; 'url:mail': 0.40; 'skip:u 10': 0.60; 'new': 0.61; 'show': 0.63; 'to:addr:gmail.com': 0.65; 'within': 0.65; 'side': 0.67; 'counts': 0.83; "'view'": 0.84; 'effects,': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=MyfP8KFfmrKy6W33Y3lq8/tTq9X6Qi5qtd5DOG8RUXs=; b=j9Pp83CrbXdWvMh/GZolc+nWPDWPBUpF4mepLjBdoHHl7lIEBqTmrBz5Rw0bhn4RDs NdOEZVkC5myL5eJXbAPJRZ6Hp/gtksPEtis+7fFYSnLDy2YgTaUll0fDpiN5FULNUyx8 NRZLcfvuRwlPwdbL9QVfx1ORX5cqzTnsOExbGKVmeozF/XMyHWWQ3wDpq1Yg3bKeqgrP AFJiGTkiJ0X8CurvV3xp15vckLvDB5ZnckpVWQmVO1KU6DBA+FiCgti58pbbL/FiP9kz SZiubUZ4S9fSI2N+wPznEWZGNWPZtZighIEr8RyHS9bJM6K52sXjG+rflxihhxcEL5tO 39jQ== MIME-Version: 1.0 X-Received: by 10.224.165.146 with SMTP id i18mr20488694qay.33.1367770720344; Sun, 05 May 2013 09:18:40 -0700 (PDT) In-Reply-To: <20130505160054.GA10521@capricorn> References: <20130505160054.GA10521@capricorn> Date: Sun, 5 May 2013 17:18:40 +0100 Subject: Re: How to avoid PEP8 'imported but unused' From: =?ISO-8859-1?Q?F=E1bio_Santos?= To: Adam Jiang Content-Type: multipart/alternative; boundary=089e0149c752ed509f04dbfaefb3 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 100 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1367770728 news.xs4all.nl 15902 [2001:888:2000:d::a6]:34899 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44749 --089e0149c752ed509f04dbfaefb3 Content-Type: text/plain; charset=ISO-8859-1 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" 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 --089e0149c752ed509f04dbfaefb3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

I usually do this on pyflakes:

import whatever
assert whatever=A0 # 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 sid= e effects, so they issue a warning anyway. Assert'ing counts as using t= he 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 i= ndicates
> 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 =3D patterns(
> =A0 =A0 '',
> =A0 =A0 url('^signup/$', 'signup')
> }
>
> # file: register.py
> def signup(request):
> =A0 =A0 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&= #39; is
> typically go into views.py. 'import' is about get 'signup&= #39; function
> into module 'views.py'. Or, I am totally wrong? Is there a pro= per way
> to avoid this warnning?
>
> Best regards,
> /Adam
> --
> http:/= /mail.python.org/mailman/listinfo/python-list

--089e0149c752ed509f04dbfaefb3--