[issue10544] yield expression inside generator expression does nothing

Guido van Rossum report at bugs.python.org
Sun Nov 26 01:22:42 EST 2017


Guido van Rossum <guido at python.org> added the comment:

No.

On Nov 25, 2017 18:01, "Nick Coghlan" <report at bugs.python.org> wrote:

>
> Nick Coghlan <ncoghlan at gmail.com> added the comment:
>
> Serhiy's PR now implements the "Prohibit yield & yield from in generator
> expressions and comprehensions" approach discussed on python-dev (currently
> as a hard SyntaxError, but it could be amended to be a warning instead
> without too much difficulty).
>
> The PR does highlight an interesting subtlety though: the easiest way to
> implement this still allows yield expressions in the outermost iterator,
> since that gets compiled in a different scope from the rest of the
> comprehension body (it's evaluated eagerly and passed in to the implicit
> nested function).
>
> I'm thinking we probably don't want to expose that detail to end users,
> and will instead want to include a second check that prohibits yield
> expressions in the outermost iterator as well. However, I'm not entirely
> sure how we could implement such a check, short of adding a new "yield
> expression prohibited" counter in the AST generation and/or symbol analysis
> pass.
>
> ----------
>
> _______________________________________
> Python tracker <report at bugs.python.org>
> <https://bugs.python.org/issue10544>
> _______________________________________
>

----------

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


More information about the Python-bugs-list mailing list