Guido van Rossum wrote:
I see this as inevitable. By the time the parser sees 'yield' it has
made its choices; the 'from' keyword cannot modify that. So whenever
"yield expr" must be parenthesized, "yield from expr" must too.

This is patently untrue, because by version of the grammar
allows 'f(yield from x)', while disallowing 'f(yield x)'.

I made a conscious decision to do that, and I'm a bit alarmed
at this decision being overridden at the last moment with no
debate.

At the same time, "yield expr, expr" works;

Um, no, that's a syntax error in any context, as far as I
can see.

but does "yield from expr, expr" mean anything?

In my current grammar, it's a syntax error on its own,
but 'f(yield from x, y)' parses as 'f((yield from x), y)',
which seems like a reasonable interpretation to me.

What's not quite so reasonable is that if you have an
expression such as

   f(x) + g(y)

and you decide to turn f into a generator, the obvious
way to rewrite it would be

   yield from f(x) + g(y)

but that unfortunately parses as

   yield from (f(x) + g(y))

If I'd thought about this more at the time, I would
probably have tried to make the argument to yield-from
something further down in the expression hierarchy,
such as a power. That might be tricky to achieve
while keeping the existing behaviour of 'yield',
though.

--
Greg
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to