[Python-ideas] Propagating StopIteration value

Serhiy Storchaka storchaka at gmail.com
Sat Oct 6 22:10:51 CEST 2012


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:

   map(lambda x: x, iterator)
   filter(lambda x: True, iterator)
   itertools.accumulate(iterator, lambda x, y: y)
   itertools.chain(iterator)
   itertools.compress(iterator, itertools.cycle([True]))
   itertools.dropwhile(lambda x: False, iterator)
   itertools.filterfalse(lambda x: False, iterator)
   next(itertools.groupby(iterator, lambda x: None))[1]
   itertools.takewhile(lambda x: True, iterator)
   itertools.tee(iterator, 1)[0]

Perhaps it would be worth to propagate original exception (or at least 
it's value) in functions for which it makes sense.




More information about the Python-ideas mailing list