Exception handling in Python 3.x
Steve Holden
steve at holdenweb.com
Tue Dec 7 18:56:29 EST 2010
On 12/7/2010 5:58 AM, John Nagle wrote:
> 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.
>
So you don't think that we should rely on iterables with no __iter__()
method to raise IndexError to terminate iterations when their
__getitem__() is called with an invalid index? The IndexError mechanism
was, to the best of my less-than-complete knowledge, used by all pre-2.2
implementations. The quoted paragraph appears to be intended to reassure
the applications programmer that there is no normal need to handle
StopIteration specially - just as there was no need to handle IndexError
specially.
> IronPython doesn't do StopIteration the same way CPython does.
>
> http://ironpython.codeplex.com/wikipage?title=IPy1.0.xCPyDifferences
>
Perhaps not, but the only difference is what happens on repeated calls
to next() after the iterator is exhausted. The iterator still terminates
by raising a StopIteration error.
I have no idea what Shed Skin does, but to the extent that iterators
don't raise StopIteration on exhaustion I'd say it is in error.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
See Python Video! http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/
More information about the Python-list
mailing list