The implementation could synthesize a generator function abusing default arguments to give the generator's frame locals with the same names.
Yes, I think that could work -- I see no way that something invoked by the generator expression could possibly modify a variable binding in the surrounding scope.
so this, if I understand:
def h(): y = 0 l = [1,2] it = (x+y for x in l) y = 1 for v in it: print v
will print 1,2 and not 2,3
def h(): y = 0 l = [1,2] def gen(S): for x in S: yield x+y it = gen(l) y = 1 for v in it: print v
Argh. Of course.
No, I think it should use the actual value of y, just like a nested function.
Never mind that idea then.
--Guido van Rossum (home page: http://www.python.org/%7Eguido/)