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

Devin Jeanpierre jeanpierreda at gmail.com
Sat Dec 13 20:02:35 CET 2014

On Sat, Dec 13, 2014 at 6:45 AM, Steven D'Aprano <steve at pearwood.info> wrote:
> It is not Python's responsibility to police that all iterators are
> non-broken. [...]
> Let's leave the iterator protocol alone.

Terry was suggesting fixing builtin iterators, not fixing all iterators or the
iterator protocol. It *is* Python's responsibility to make sure the
builtin iterators are not broken. It's fine and to be expected if user
code raises StopIteration, but map and filter don't handle it
correctly and therefore disobey the iterator protocol, which is a bug
in map and filter -- not the callback.

-- Devin

More information about the Python-ideas mailing list