[Python-projects] PyLint: scope of variable of list comprehension
Sylvain Thénault
sylvain.thenault at logilab.fr
Thu Jul 20 10:49:15 CEST 2006
On Wednesday 19 July à 21:37, Maarten ter Huurne wrote:
>
> python-projects-bounces at lists.logilab.org wrote on 2006-07-19 09:25:07 PM:
>
> > > But if I run this code in Python, there is no variable named "n" in
> > > the global scope. So it seems that in this respect, the "for" of a
> > > list comprehension / generator expression is different than the "for"
> > > statement.
> >
> > This is only true for generator expressions. With list comprehensions
> > the name is "leaking"::
>
> You are right.
>
> I first encountered the problem with a generator expression which created a
> dictionary. Then I made the test case with a list, since that required less
> code. Then I noticed list comprehension triggers the same warning, but I forgot
> to verify that "n" was undefined (and in fact, it is "leaking" and thus
> defined).
>
> So please ignore the part about list comprehension, but the bug is valid for
> generator expressions.
Yep. And it'll be also true for lists comprehensions in a near future (2.5?).
I add this to our tracker.
> (Does Debian have Python 2.4 as the default by now? ;)
not yet :/
--
Sylvain Thénault LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian: http://www.logilab.fr/formations
Développement logiciel sur mesure: http://www.logilab.fr/services
Python et calcul scientifique: http://www.logilab.fr/science
More information about the Python-Projects
mailing list