[Python-Dev] Don't set local variable in a list comprehension or generator

Nick Coghlan ncoghlan at gmail.com
Wed May 18 16:17:28 CEST 2011

On Wed, May 18, 2011 at 10:21 PM, Victor Stinner
<victor.stinner at haypocalc.com> wrote:
> What do you think? Is it useless and/or stupid?

I wouldn't call it useless or stupid - merely "lost in the noise". In
small cases, I expect it would be swamped completely by the high fixed
overhead of entering the new scope and in all generator expressions I
expected it would be swamped by the cost of resuming the generator on
each iteration, and even for comprehensions any time spent on the
unneeded variable assignment is likely still going to be dominated by
the __next__() call overhead.

> I heard about optimization in the AST tree instead of working on the
> bytecode. What is the status of this project?

First step is getting back to Eugene Toder's AST cleanup patch and
working on getting that in. It's a big patch though, and I'd like to
see it broken up into a couple of distinct phases before we proceed.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-Dev mailing list