[Python-ideas] Propagating StopIteration value
Steven D'Aprano
steve at pearwood.info
Sun Oct 7 03:09:44 CEST 2012
On 07/10/12 07:10, Serhiy Storchaka wrote:
> As StopIteration now have value, this value is lost when using functions which
>works with iterators/generators (map, filter, itertools). Therefore, wrapping
>the iterator, which preserved its semantics in versions before 3.3, no longer
> preserves it:
[...]
> Perhaps it would be worth to propagate original exception (or at least it's
>value) in functions for which it makes sense.
A concrete example would be useful for those who don't know about the (new?)
StopIteration.value attribute. I think you are referring to this:
py> def myiter():
... yield 1
... raise StopIteration("spam")
...
py> it = map(lambda x:x, myiter())
py> next(it)
1
py> next(it)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
The argument given to StopIteration is eaten by map.
But this is not *new* to 3.3, it goes back to at least 2.4, so I'm
not sure if you are talking about this or something different.
--
Steven
More information about the Python-ideas
mailing list