[Python-3000] Is this a bug with list comprehensions or not?

Raymond Hettinger python at rcn.com
Fri Jul 11 09:00:36 CEST 2008


From: "Guido van Rossum" <guido at python.org>
> The new failure in 3.0 is a side effect of the translation (mostly) of
> list comps into genexps. The underlying problem is that the genexp
> creates a function scope, and function scopes don't have access to the
> surrounding class body scope. (There's a really good but extremely
> subtle reason for that.)

Would you be open to an alternate implementation for list/set/dict comps
that doesn't use a genexps?  That would solve the scope problem, 
the performance hit, and make tracing more straight-forward.

If you're open to it, I can see if the EuroPython sprinters can find an 
implementation closer to what we had before but using the compiler 
to create an invisible induction variable.

Not sure if the current implementation was really a winning trade. 
It may have been better to have the minor but easy to explain nuisance
of exposing the induction variable instead of having the harder-to-explain
subtleties associated with a slower underlying genexp.


Raymond


More information about the Python-3000 mailing list