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 gvanrossum
Recipients Inyeol.Lee, Jim Fasarakis-Hilliard, belopolsky, benjamin.peterson, danielsh, emptysquare, erickt, esc24, georg.brandl, glyph, gvanrossum, ncoghlan, rhettinger, serhiy.storchaka, yselivanov
Date 2017-11-26.17:58:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CAP7+vJLE0P_JAdpyWvg=75+9C5kKpkV5QZCW+3WRy++qp_=ucA@mail.gmail.com>
In-reply-to <CAP7+vJ+t9rZeQ_9UJ4LSrZg6SwpG4g2FyOy=OKJpu3YoQ6JcAQ@mail.gmail.com>
Content
To clarify, the outermost iterator is marked here:

    [func(x, y) for x in <outermost iterator> for y in <something else>]

and it is evaluated before the comprehension proper is started. This is
just part of how the language works (it's a similar rule as "in an
assignment the RHS is evaluated before it is assigned to the LHS").

I see no benefit in banning `yield` in <outermost iterator>.

On Sat, Nov 25, 2017 at 10:22 PM, Guido van Rossum <report@bugs.python.org>
wrote:

>
> Guido van Rossum <guido@python.org> added the comment:
>
> No.
>
> On Nov 25, 2017 18:01, "Nick Coghlan" <report@bugs.python.org> wrote:
>
> >
> > Nick Coghlan <ncoghlan@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@bugs.python.org>
> > <https://bugs.python.org/issue10544>
> > _______________________________________
> >
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue10544>
> _______________________________________
>
History
Date User Action Args
2017-11-26 17:58:23gvanrossumsetrecipients: + gvanrossum, georg.brandl, rhettinger, ncoghlan, belopolsky, benjamin.peterson, erickt, glyph, Inyeol.Lee, serhiy.storchaka, yselivanov, esc24, danielsh, emptysquare, Jim Fasarakis-Hilliard
2017-11-26 17:58:23gvanrossumlinkissue10544 messages
2017-11-26 17:58:23gvanrossumcreate