[Python-Dev] listcomps vs. for loops

Jp Calderone exarkun at intarweb.us
Tue Oct 21 13:31:25 EDT 2003

On Tue, Oct 21, 2003 at 09:56:31AM -0700, Guido van Rossum wrote:
> > >  Anyway, this is no different from the
> > > problem of:
> > >
> > >     for x in R:
> > >         ...
> > >     print x
> > 
> > Well, yes.  I still think it's dubious code.
> > 
> > > In any case, are there plans to also have the compiler emit
> > > warnings about potential reliance on this feature?
> > 
> > I would hope that we wouldn't make changes without emitting such a
> > warning.  I'm not sure how hard it would be to implement, tho'.
> Warning about what?
> I have no intent to make the example quoted above illegal; a regular
> for loop control variable's scope will extend beyond the loop.

  Sorry, my ordering could have been a little more clear.  I only meant a
warning for the list comprehension case.
> [snip]
> Do you need a warning for that change too?  Code that relies on it is
> pretty sick IMO.

  I agree, and I try never to write such code.  But having Python point out
any places I foolishly did so makes the job of fixing any bugs this change
introduces into my code that much easier.

  It also serves to point out to people who *don't* realize how sick this
construct is that a potentially large chunk of their software will break in
Python X.Y (3.0?), where it will break, and why it will break.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/python-dev/attachments/20031021/59d36242/attachment.bin

More information about the Python-Dev mailing list