[issue7423] nested generator expression produces strange results

2014-07-02 Thread Steve Holden
Steve Holden added the comment: In my experience the devs are pretty well in touch with the user base (though they don't always acknowledge its input). If you leave a programming language at the first sign of wart I fear yo may eventually run out of languages. -- nosy: +holdenweb ___

[issue7423] nested generator expression produces strange results

2013-02-27 Thread Christopher King
Christopher King added the comment: *At this point you need to take your arguments to python-ideas or python-dev (probably the latter),* I used Python once and will probably never use it again. I'm not nearly invested enough to evangelize on several mailing lists the validity of a bug that I

[issue7423] nested generator expression produces strange results

2013-02-26 Thread R. David Murray
R. David Murray added the comment: Well, we're a bit more nuanced about backward compatibility than that :) I doubt that people *intentionally* rely on the behavior, true, so a change could conceivably be made in a new release. At this point you need to take your arguments to python-ideas or p

[issue7423] nested generator expression produces strange results

2013-02-26 Thread Christopher King
Christopher King added the comment: > I hear what you are saying, but the "generalization" does not mean > that they work exactly the same way. Correct. But it does mean that the functionality of one (generator expressions) is a superset of the functionality of the other (list comprehensions)

[issue7423] nested generator expression produces strange results

2013-02-26 Thread R. David Murray
R. David Murray added the comment: To be honest I don't understand the sentence from Guido that you are quoting (even reading the issue I don't think I have the full context), but what we wound up with was what he wound up wanting. -- ___ Python tra

[issue7423] nested generator expression produces strange results

2013-02-26 Thread R. David Murray
R. David Murray added the comment: I hear what you are saying, but the "generalization" does not mean that they work exactly the same way. The whole point of generators is that execution is lazy, which is what leads to the difference in behavior. The generator function *is* closed over the

[issue7423] nested generator expression produces strange results

2013-02-26 Thread Christopher King
Christopher King added the comment: Quote from Guido: """In general the value of every free variable used anywhere except in the outer expression should be captured; [...] This should give the least surprising semantics in a variaty of use cases.""" Source: http://bugs.python.org/issue872326

[issue7423] nested generator expression produces strange results

2013-02-26 Thread Christopher King
Christopher King added the comment: Only the implementation of *generators* needs to change to remedy this bug. Please see the example I included. By closing the generated generator function over free the free variables in the generator expression, you can avoid dynamic scoping entirely and

[issue7423] nested generator expression produces strange results

2013-02-26 Thread R. David Murray
R. David Murray added the comment: The behavior is deeply baked into how Python does closures and scoping. It shows up elsewhere than generators (eg: nested function definitions; usually encountered when using lambdas). So, this behavior isn't going to change, it's just one of a relatively sm

[issue7423] nested generator expression produces strange results

2013-02-26 Thread Christopher King
Christopher King added the comment: Also tested and broken in Py3k. -- versions: +Python 3.2 ___ Python tracker ___ ___ Python-bugs-lis

[issue7423] nested generator expression produces strange results

2013-02-26 Thread Christopher King
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 comp

[issue7423] nested generator expression produces strange results

2009-12-01 Thread R. David Murray
R. David Murray added the comment: I'd already written then when Benjamin posted his answer, but rather than waste having written it I'm going to post it anyway :) You must remember that the purpose of a generator is to evaluate lazily. Your expression involving the generator would unwrap this

[issue7423] nested generator expression produces strange results

2009-12-01 Thread Benjamin Peterson
Benjamin Peterson added the comment: By using a generator expression, you are deferring evaluation of the expression until map() is actually invoked. By that time, the closure over 'x' has been changed to 'b', so when the genexp is forced, 'x' yields 'b' each time. -- nosy: +benjamin.pe

[issue7423] nested generator expression produces strange results

2009-12-01 Thread bogklug
New submission from bogklug : The first of the two maps below gives strange result due to the nested generator expression (I guess it should give the same result as the second map). In [1]: map(list, [(x+y for y in 'c') for x in 'ab']) Out[1]: [['bc'], ['bc']] In [2]: map(list, [[x+y for y in '