[Python-ideas] Map and filter should also convert StopIteration to RuntimeError

Steven D'Aprano steve at pearwood.info
Sun Dec 14 02:34:18 CET 2014

On Sat, Dec 13, 2014 at 06:37:16PM -0500, Terry Reedy wrote:

> I have two alternate proposals.
> 1. In the doc entry for StopIteration, explicitly recommend against 
> raising StopIteration outside of __next__ methods on the basis that 
> doing so can lead to silent breakage of iterators.  Then writing 
> functions that do so anyway or passing them into iterators will clearly 
> be a 'consenting adults' issue.

I think that is reasonable.

> 2. Make it easier to avoid accidentally leaking StopIteration when using 
> next() by adding an option to have it raise a different exception.  I 
> already posted this idea to a different thread.

I think that is adding complexity that isn't needed.


More information about the Python-ideas mailing list