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

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


Guido van Rossum wrote:

> That +0 could turn into a +1 if there was a way to flag this as an
> error (at runtime), at least if the return is actually executed:
> 
> def g():
>     yield 42
>     return 43
> 
> for x in g():
>     print x    # probably expected to print 42 and then 43
> 
> Perhaps the exception used in this case could be a different exception
> than StopIteration?

Would checking that the value is None be sufficient? Or do you
want to distinguish between 'return' and 'return None'? That
would feel rather strange to me.

I'm inclined to regard this as an unnecessary complication.
People are already trained to think of 'return' and 'yield'
as quite different things. I don't know why they would suddenly
start using 'return' when they mean 'yield'.

-- 
Greg


More information about the Python-Dev mailing list