[Python-Dev] PEP 380 (yield from a subgenerator) comments

Guido van Rossum guido at python.org
Fri Mar 27 20:23:06 CET 2009

On Fri, Mar 27, 2009 at 1:06 AM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> P.J. Eby wrote:
>> Could we at least have some syntax like 'return from yield with 43', to
>> distinguish it from a regular return, clarify that it's returning a value to
>> a yield-from statement, and emphasize that you need a yield-from to call it?
> You don't, though -- yield-from just happens to be a particularly
> convenient way.
> I suppose what you really mean is that you can't just use an
> ordinary call. But generators already have that property,
> whether they return values or not, and they're already
> syntactically marked as such by containing 'yield'. I don't
> see that we need a second syntactic marker.

Because for vanilla generators a return is always a mistake.

>> If it doesn't have some sort of variant syntax, the error message for the
>> return exception is going to need to be rather verbose
> If we're going to treat this as an error at all, I imagine
> it would say something like "Return value from generator not
> used." RTM to sort out the details.

That would be fine with me.

>> One remaining quirk or missing piece: ISTM there needs to be a way to
>> extract the return value without using a yield-from statement.
> I did suggest a for-loop variant for doing this, but Guido warned
> me not to complicate the PEP any further, so I haven't. A followup
> PEP for it might be in order.

I don't think this is a requirement, though I expect there will be a
way since the error will result into some kind of exception, which
means you'll be able to catch it by explicitly invoking __next__().

(BTW, at the language summit we reached the conclusion that proposed
language changes need to be aimed at Py3k first (3.1 in this case) and
backported to 2.x -- 2.7 in this case. You might want to tweak the
proposal to apply to 3.x by default.)

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the Python-Dev mailing list