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 ncoghlan
Recipients alexandre.vassalotti, georg.brandl, ncoghlan, scoder
Date 2009-08-14.23:53:09
SpamBayes Score 1.01525e-06
Marked as misclassified No
Message-id <1250293992.31.0.654784797797.issue6673@psf.upfronthosting.co.za>
In-reply-to
Content
Reopening - this should be rejected by the compiler as a SyntaxError,
since it is the comprehension equivalent of writing "return Value"
inside a generator function.

Specifically, in 3.x, the equivalent written out code is:

    while True:
        def _listcomp():
            result = []
            for i in range(chunk_size):
                result.append((yield))
            return result # Would trigger SyntaxError!
        target.send(_listcomp())

As noted in the comment, the compiler would disallow that expansion with
a SyntaxError on the marked line, so the comprehension equivalent should
be rejected as well. This also applies to dict and set comprehensions.

Generator expressions are slightly less clear, since their expanded
equivalent would produce legal code:

>>> g = ((yield)*(yield) for i in range(1))
>>> next(g)
>>> g.send(2)
>>> g.send(3)
6
>>> next(g)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

That first line is roughly equivalent to:
        def _genexp():
            for i in range(1):
                yield (yield)*(yield)
        g = _genexp()

So the compiler should probably be keeping track of whether it is inside
a comprehension or not to decide whether or not to allow yield expressions.
History
Date User Action Args
2009-08-14 23:53:12ncoghlansetrecipients: + ncoghlan, georg.brandl, scoder, alexandre.vassalotti
2009-08-14 23:53:12ncoghlansetmessageid: <1250293992.31.0.654784797797.issue6673@psf.upfronthosting.co.za>
2009-08-14 23:53:10ncoghlanlinkissue6673 messages
2009-08-14 23:53:09ncoghlancreate