[Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

Greg Ewing greg.ewing at canterbury.ac.nz
Sun Dec 9 01:09:15 CET 2007

Manuel Alejandro Cerón Estrada wrote:

 > Acording to PEP 255:
>     Note that return isn't always equivalent to raising StopIteration:  the
>     difference lies in how enclosing try/except constructs are treated.

All that means is that

   def g():
       if 0:
     except StopIteration:
       print "Spam"

won't print "Spam". But since this involves catching the
exception with an explicit try-except, it doesn't fall
under the scope of your complaint.

> Of curse, the problem of low level details it's solved by 'yield break'

I would put it the other way around -- the problem
that 'yield break' is meant to solve is already solved
by 'return'. So there's no need for change.


More information about the Python-Dev mailing list