[Python-Dev] [872326] generator expression implementation

Jeremy Hylton jeremy at alum.mit.edu
Mon Jan 12 10:41:48 EST 2004

On Mon, 2004-01-12 at 05:58, Armin Rigo wrote:
> Sorry to bring this out again, I didn't find a reference about the following 
> issue in generator expressions:
>   (for x in expr)
> When should 'expr' be evaluated?  A priori, one would expect it to be 
> evaluated immediately, but it is not what the suggested implementation does:
> def __gen():
>   for x in expr:
>     yield x
> __gen()

First a quick clarification:  Is the "suggested implementation" SF patch
872326 or is it that implementation sketch in PEP 289?  The latter
certainly suggests it, but it's hard to tell even then if it's
intentional.  Perhaps we should work out the formal specification part
of the PEP in parallel with the implementation.  The PEP currently says
that the reference manual should contain a specification, but that spec
is supposed to be part of the PEP, too.

I agree, at any rate, that the expression should be evaluated
immediately.  That's easy enough to implement:

def __gen(it):
    for x in it:
        yield x


More information about the Python-Dev mailing list