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

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Mar 27 07:06:44 CET 2009


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.

> 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.

> 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.

-- 
Greg


More information about the Python-Dev mailing list