[Python-ideas] Propagating StopIteration value

Serhiy Storchaka storchaka at gmail.com
Sun Oct 7 21:30:16 CEST 2012

On 07.10.12 04:45, Guido van Rossum wrote:
> But yes, this was all considered and accepted when PEP 380 was debated
> (endlessly :-), and I see no reason to change anything about this.

The reason is that when someone uses StopIteration.value for some 
purposes, he will lose this value if the iterator will be wrapped into 
itertools.chain (quite often used technique) or into other standard 
iterator wrapper.

> "Don't do that" is the best I can say about it -- there are a zillion
> other situations in Python where that's the only sensible motto.

The problem is that two different authors can use two legal techniques 
(using values returned by "yield from" and wrap iterators with 
itertools.chain) which do not work in combination. The conflict easily 
solved if instead of standard itertools.chain to use handwriten code. It 
looks as bug in itertools.chain.

More information about the Python-ideas mailing list