[issue7423] nested generator expression produces strange results

Christopher King report at bugs.python.org
Tue Feb 26 20:23:01 CET 2013


Christopher King added the comment:

This is a crazy and unexpected behavior.  (Moreover, the fact that Python has dynamic scope *only if you forget to initialize a variable* is even more crazy and unexpected.)  To provide unsurprising behavior (i.e. behavior compatible with that of a list comprehension) the generator above should "unwrap" (i.e. reduce) to:

def g1(x):
    for y in 'c':
        yield x+y
l = []
for x in 'ab':
    l.append(g1(x))
print l
print map(list, l)

i.e. the variables referenced by, but not initialized by, the innermost generator should add extra parameters to the generated generator function.

----------
nosy: +Christopher.King

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7423>
_______________________________________


More information about the Python-bugs-list mailing list