Zen of Python

Andrew Koenig ark at acm.org
Sat Jan 22 18:33:49 CET 2005


"Paul Rubin" <http://phr.cx@NOSPAM.invalid> wrote in message 
news:7x8y6l8k6l.fsf at ruckus.brouhaha.com...

> It's not obvious to me how the compiler can tell.  Consider:
>
>    x = 3
>    if frob():
>       frobbed = True
>       squares = [x*x for x in range(9)]
>    if blob():
>       z = x
>
> Should the compiler issue a warning saying the program should be taken
> out and shot?  With lexical comprehensions, the program is perfectly
> valid and sets z to 3 if blob() is true.  The whole point of lexical
> comprhensions is to make Python safe for such programs.
>
> Without lexical comprehensions, the program still doesn't depend on
> the listcomp leakage if frob() and blob() aren't simultaneously true
> (envision "assert not frobbed" before the "z = x").  So "should be
> taken out and shot" is maybe a little bit extreme.

Actually, I don't think so.  If you intend for it to be impossible for "z = 
x" to refer to the x in the list comprehension, you shouldn't mind putting 
in "from __future__ import lexical_comprehensions."  If you don't intend for 
it to be impossible, then the program *should* be taken out and shot.





More information about the Python-list mailing list