[New-bugs-announce] [issue20663] Introduce exception argument to iter

Ram Rachum report at bugs.python.org
Mon Feb 17 18:43:47 CET 2014

New submission from Ram Rachum:

See discussion: https://groups.google.com/forum/#!searchin/python-ideas/iter/python-ideas/UCaNfAHkBlQ/5vX7JbpCxDkJ

`iter` has a very cool `sentinel` argument. I suggest an additional argument `exception`; when it's supplied, instead of waiting for a sentinel value, we wait for a sentinel exception to be raised, and then the iteration is finished.

This'll be useful to construct things like this: 

    my_iterator = iter(my_deque.popleft, exception=IndexError)

I also suggest being able to pass multiple exceptions in a tuple to have any of them trigger a `StopIteration`.

components: Interpreter Core
messages: 211431
nosy: cool-RR, terry.reedy
priority: normal
severity: normal
status: open
title: Introduce exception argument to iter
type: enhancement
versions: Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list