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

Greg Ewing greg.ewing at canterbury.ac.nz
Sat Mar 28 07:36:42 CET 2009

Guido van Rossum wrote:

> The new exception could either be a designated (built-in) subclass of
> StopIteration, or not;

I think it would have to not be; otherwise any existing
code that catches StopIteration would catch the new
exception as well without complaint.

Using a different exception raises another question.
Would you check whether the return value is None and
raise an ordinary StopIteration in that case? Or would
return with a value always raise the new exception?

If the latter, then 'return' and 'return None' would
no longer be equivalent in all cases, which would be
rather strange.

> I think in either case a check in
> PyIter_Next() would cover most cases

If that's acceptable, then the check might as well
be for None as the StopIteration value, and there's
no need for a new exception.


More information about the Python-Dev mailing list