Nick Coghlan <ncogh...@gmail.com> added the comment: 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. ---------- keywords: +64bit nosy: +ncoghlan resolution: invalid -> _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6673> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com