[issue5577] yield in iterators

2009-03-27 Thread Guido van Rossum
Guido van Rossum added the comment: Fine! -- resolution: -> wont fix status: open -> closed ___ Python tracker ___ ___ Python-bugs-li

[issue5577] yield in iterators

2009-03-27 Thread Terry J. Reedy
Terry J. Reedy added the comment: I think this should just be closed. The original implied claim that 3.0 is not correct is not correct. The change of behavior is a clear side effect of and intended and documented change in the semantics of comprehensions. As near as I can tell, the results o

[issue5577] yield in iterators

2009-03-27 Thread Guido van Rossum
Guido van Rossum added the comment: Can anyone think of a *reason* to put a yield inside a generator expression? ISTM we could just forbid this syntactically. It seems insane and hard to read so if someone has a reason they should write it out using an explicit for-statement. -- nosy:

[issue5577] yield in iterators

2009-03-27 Thread qwjqwj
qwjqwj added the comment: Ok, I see. Thanks. However, I don't think yield should be consumed at the iterator's level. It may be more useful for the outside function to consume the yield. For example, some function want to change some data with another "thread". def f(): ...fetch data...

[issue5577] yield in iterators

2009-03-27 Thread Antoine Pitrou
Antoine Pitrou added the comment: > More experiments: > The tuple pair (10,20) don't correspond to (i,i*i) This is normal, since it corresponds to ((yield i), (yield i*i)). The value of a yield expression is what the caller puts into send(), not what is yielded to the caller. And since you sent

[issue5577] yield in iterators

2009-03-27 Thread qwjqwj
qwjqwj added the comment: More experiments: The tuple pair (10,20) don't correspond to (i,i*i) The yield order is distorted >>> x = (((yield i),(yield i*i)) for i in range(3)) >>> x.__next__() 0 >>> x.send(10) 0 >>> x.send(20) (10, 20) >>> x.send(30) 1 >>> x.send(40) 1 >>> x.send(60) (40, 60) >

[issue5577] yield in iterators

2009-03-27 Thread qwjqwj
qwjqwj added the comment: >>> x = {(yield i) for i in range(10)} >>> x at 0x02A453F0> >>> list(x) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, {None}] -- ___ Python tracker ___ __

[issue5577] yield in iterators

2009-03-27 Thread qwjqwj
qwjqwj added the comment: >>> x = ((yield i) for i in range(10)) >>> list(x) [0, None, 1, None, 2, None, 3, None, 4, None, 5, None, 6, None, 7, None, 8, None, 9, None] -- ___ Python tracker

[issue5577] yield in iterators

2009-03-27 Thread qwjqwj
qwjqwj added the comment: Why should yield can be put inside the iterator? The behavior here is very weired. >>> x = [(yield i) for i in range(10)] >>> print(list(x)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, [None, None, None, None, None, None, None, None, None, None]] -- __

[issue5577] yield in iterators

2009-03-27 Thread Antoine Pitrou
Antoine Pitrou added the comment: It's true, however, that there is a difference in behaviour between 2.x and 3.x here. In 2.x, the function containing the list comprehension is a generator. In 3.x, it's the list comprehension itself which becomes a generator. I'm not sure which one is more usef

[issue5577] yield in iterators

2009-03-27 Thread Antoine Pitrou
Antoine Pitrou added the comment: Perhaps you forgot to return the value. In 3.1: >>> def f(): ... return [(yield i) for i in range(10)] ... >>> f() at 0x7f9bcc2257d0> -- nosy: +pitrou ___ Python tracker __

[issue5577] yield in iterators

2009-03-27 Thread qwjqwj
New submission from qwjqwj : In Python 3.0,3.1a1: >>> def f(): [(yield i) for i in range(10)] >>> f() >>> f() is None True >>> def f(): ((yield i) for i in range(10)) >>> f() >>> f() is None True However it is correct in Python 2.5,2.6 >>> def f(): ... [(yield i) for i in