Is StopIteration a singleton?

Chris Angelico rosuav at gmail.com
Thu Nov 20 02:52:25 CET 2014


While poking about the cpython source tree with reference to PEP 479,
I came across this:

https://docs.python.org/3.5/library/marshal.html

"""singletons None, Ellipsis and StopIteration can also be marshalled
and unmarshalled."""

StopIteration is a type. I suppose it's still kinda true that there's
only one StopIteration class (otherwise exception handling would get
very messy), but it seems unusual that this one particular exception
class should be special-cased. (And yes, the code does correspond -
marshal.c:293 handles StopIteration with its own byte code.)

Why is StopIteration marshallable but no other exception is? Or, if
they are marshallable, why does this one get special handling?

ChrisA



More information about the Python-list mailing list