[Python-ideas] sentinel_exception argument to `iter`
Terry Reedy
tjreedy at udel.edu
Fri Feb 7 05:15:14 CET 2014
On 2/6/2014 9:45 PM, Chris Angelico wrote:
> On Fri, Feb 7, 2014 at 1:36 PM, Terry Reedy <tjreedy at udel.edu> wrote:
>> def __next__(self):
>> try:
>> x = self.func()
>> except Exception as exc:
>> if isinstance(exc, self.sentinel):
>> raise StopIteration from None
else:
raise
>> if x == self.sentinel:
>> raise StopIteration
>> else:
>> return x
>
> Forgive me if this is a stupid question, but wouldn't this suppress
> any other thrown exception? I'm looking for a bare 'raise' inside the
> except block,
which should be there. As I said, but you snipped, '(untested)'
> such that any exception is guaranteed to raise
> something, but if it's a subclass of self.sentinel, it raises
> StopIteration instead.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list