[Python-Dev] Iteration variables and list comprehensions
Greg Ward
gward@python.net
Tue, 29 May 2001 17:21:55 -0400
On 29 May 2001, David Beazley said:
> Therefore, I'm wondering if it would make any sense to make the
> iterator variables used inside of a list comprehension private in some
> manner--either through name mangling or some other technique? For
> example:
Two ideas occur to me:
* make the list comprehension a new scoping level, which of course
is doable now that we have sensible scoping semantics. Presumably
the usual warning message about shadowing variables from an
outer scope will apply; you'll still have the bug in your code,
but at least Python will tell you about it
* don't make list comprehensions a separate scope, but add a
little trickery so that something *like* the "shadowing variable
from an outer scope" message is emitted
Haven't really thought about backwards compatibility issues...
Greg