Hello, I've noticed a surprising behavior of first() which can be well illustrated by:
print(list(map(
first,
[[1,2,3], [], [1,2,3], [1,2,3]]
)))
I would expect this statement to raise an exception, because first([]) normally raises an exception on an empty sequence. However, the exception is StopIteration which seems to interfere with map and stops its iteration.
What do you think about catching StopIteration in first() and re-raising a different exception, so it can propagate until explicitly caught? Which exception would be appropriate?
Hello, I've noticed a surprising behavior of
first()which can be well illustrated by:I would expect this statement to raise an exception, because
first([])normally raises an exception on an empty sequence. However, the exception isStopIterationwhich seems to interfere withmapand stops its iteration.What do you think about catching
StopIterationinfirst()and re-raising a different exception, so it can propagate until explicitly caught? Which exception would be appropriate?