[Python-projects] PyLint: scope of variable of list comprehension
Maarten ter Huurne
maarten.ter.huurne at philips.com
Wed Jul 19 21:37:30 CEST 2006
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.
(Does Debian have Python 2.4 as the default by now? ;)
Bye,
Maarten
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.logilab.org/pipermail/python-projects/attachments/20060719/adbedf6f/attachment.htm
More information about the Python-Projects
mailing list