[Python-ideas] Map and filter should also convert StopIteration to RuntimeError
tjreedy at udel.edu
Sat Dec 13 03:35:03 CET 2014
On 12/12/2014 7:36 PM, Greg Ewing wrote:
> Terry Reedy wrote:
"I have always taken this to mean that [next and __next__] are the only
functions that should raise StopIteration," ...
>> PEP 479 reverses this acceptance by having generator.__next turn
>> StopIteration raised in a user-written generator function body into a
>> RuntimeError. I propose that other builtin iterator.__next__ methods
>> that execute a passed in function do the same.
> Maybe also any user-written function whose
> name isn't "__next__"?
That such functions should catch StopIteration (most likely from next)
is implied in the paragraph's opening sentence, repeated above. What
the replacement should be is a different matter. There are often better
choices than RuntimeError.
Terry Jan Reedy
More information about the Python-ideas