Gerald Britton wrote:
I wonder if this is a bug?

It is a known glitch reported last summer. Devs decided not to fix because doing so would, in the patches tried, slow list comps significantly. Also, the documented intent and expected usage of StopIteration is this

"exception StopIteration
Raised by builtin next() and an iterator‘s __next__() method to signal that there are no further values."

The second clause includes usage in the body of a generator function since that body becomes the __next__ method of the generator-iterator produced by calling the generator function.

The meaning of any other usage, such as in the body of a standard function other than next(),(as in the example producing the glitch), is undefined and leads to undefined behavior, which could be different in other implementations and change in future implementations.

Terry Jan Reedy

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to