Closed as not planned
Description
Feature or enhancement
Proposal:
map
expressions propagate the .value
field of StopIteration
exceptions. for
expressions do not. It is surprising that these two similar constructs have different behaviour in this way, and this violates the Principle of Least Surprise. for
expressions should be made to also propagate .value
.
def gen():
yield 1
yield 2
return "Hello"
map_it = map(lambda x: x + 10, gen())
for_it = (x + 10 for x in gen())
assert next(map_it) == 11
assert next(for_it) == 11
assert next(map_it) == 12
assert next(for_it) == 12
try:
next(map_it)
except StopIteration as exc:
assert exc.value == "Hello"
try:
next(for_it)
except StopIteration as exc:
assert exc.value == None # current behaviour
# assert exc.value == "Hello" # proposed behaviour
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response