[issue2217] Problem with if clause in generator expression on class level

Christoph Zwerschke report at bugs.python.org
Sun Mar 2 23:27:56 CET 2008

Christoph Zwerschke added the comment:

Thanks, this now makes sense to me. You're right, it's rather an ugly
wart than a bug.

But I think the Python reference needs to be improved to make this clear

How about the following proposed addtions (in square brackets) to
section 5.2.5 (http://docs.python.org/ref/genexpr.html):

"Variables used in the generator expression are evaluated lazily [in the
scope of the generator function] when the next() method is called for
[the] generator object (in the same fashion as normal generators).
However, the leftmost for clause is immediately evaluated [in the
current scope] so that [an] error produced by it can be seen before any
other possible error in the code that handles the generator expression.
Subsequent for [and if] clauses cannot be evaluated immediately since
they may depend on the previous for loop."

Tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list