[issue10544] yield expression inside generator expression does nothing

Nick Coghlan report at bugs.python.org
Fri Nov 24 22:57:17 EST 2017


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Given the direction of the python-dev thread, should we split this question into two issues?

Issue 1: a yield expression inside a comprehension changes the type of the expression result (returning a generator-iterator instead of the expected container type)

Issue 2: a yield expression inside a generator expression interacts weirdly with the genexp's implicit yield expression

I ask, as it seems to me that issue 1 can be addressed by wrapping the affected cases in an implicit 'yield from' expression, which will both fix the return type of the expression and turn the outer function into a generator (if it isn't one already). (I'm going to put together a proof-of-concept for that idea this weekend)

By contrast, the interaction between generator expressions and explicit yield expressions seems intrinsically confusing, so I'm not sure we can do any better than declaring it a syntax error to try to combine them.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue10544>
_______________________________________


More information about the Python-bugs-list mailing list