This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author erickt
Recipients erickt
Date 2008-07-03.06:28:17
SpamBayes Score 0.00013178111
Marked as misclassified No
Message-id <1215066499.8.0.630576860475.issue3267@psf.upfronthosting.co.za>
In-reply-to
Content
This may be a known consequence of python 3.0, but I couldn't find any 
reference to it, nor a test case that covers it. Here's a valid use of yield 
in 2.5.1:

>>> def foo():
...   x=[(yield x) for x in 1,2,3]
...   yield 5
...   yield x
>>> x=foo()
>>> x.next()
1
>>> x.send(6)
2
>>> x.send(7)
3
>>> x.send(8)
5
>>> x.send(9)
[6, 7, 8]
>>> x.send(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration


But in python 3.0, this code results in:

>>> def foo():
...   x=[(yield x) for x in (1,2,3)]
...   yield 5
...   yield x
>>> x=foo()
>>> next(x)
5
>>> x.send(6)
<generator object <listcomp> at 0x3678f0>
>>> x.send(7)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration


Looking further, it seems that this is a comprehension:

>>> def foo(): [(yield 5)]
>>> type(foo())
<class 'generator'>

Whereas this is not:

>>> def foo(): [(yield 5) for x in range(3)]
>>> type(foo())
<class 'NoneType'>


Is this expected behavior?
History
Date User Action Args
2008-07-03 06:28:20ericktsetspambayes_score: 0.000131781 -> 0.00013178111
recipients: + erickt
2008-07-03 06:28:19ericktsetspambayes_score: 0.000131781 -> 0.000131781
messageid: <1215066499.8.0.630576860475.issue3267@psf.upfronthosting.co.za>
2008-07-03 06:28:18ericktlinkissue3267 messages
2008-07-03 06:28:18ericktcreate