Exception handling in Python 3.x

John Nagle nagle at animats.com
Mon Dec 6 23:58:48 EST 2010


On 12/6/2010 2:24 PM, Mark Wooding wrote:
> John Nagle<nagle at animats.com>  writes:
>
>> Right.  You're not entitled to assume that StopIteration is how a
>> generator exits.  That's a CPyton thing; generators were a retrofit,
>> and that's how they were hacked in.  Other implementations may do
>> generators differently.
>
> This is simply wrong.  The StopIteration exception is a clear part of
> the generator protocol as described in 5.2.8 of the language reference;
> the language reference also refers to 3.5 of the library reference,
> which describes the iterator protocol (note, not the generator
> implementation -- all iterators work the same way), and explicitly
> mentions StopIteration as part of the protocol.
>
> -- [mdw]

    PEP 255, like too much Python literature, doesn't distinguish clearly
between the language definition and implementation detail. It says
"The mechanics of StopIteration are low-level details, much like the
mechanics of IndexError in Python 2.1".  Applications shouldn't be
explicitly using StopIteration.

    IronPython doesn't do StopIteration the same way CPython does.

http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences

    Neither does Shed Skin.

					John Nagle



More information about the Python-list mailing list