[Python-ideas] Propagating StopIteration value
Guido van Rossum
guido at python.org
Sun Oct 7 22:19:11 CEST 2012
On Sun, Oct 7, 2012 at 12:30 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> 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.
If this is just about iterator.chain() I may see some value in it (but
TBH the discussion so far mostly confuses -- please spend some more
time coming up with good examples that show actually useful use cases
rather than f() and g() or foo() and bar())
OTOH yield from is not primarily for iterators -- it is for
coroutines. I suspect most of the itertools functionality just doesn't
work with coroutines.
>> "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.
Okay, so please do work out a complete, useful use case. We may yet
see the light.
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas