[Python-ideas] Propagating StopIteration value
Guido van Rossum
guido at python.org
Tue Oct 9 00:44:12 CEST 2012
On Mon, Oct 8, 2012 at 2:02 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> On 07.10.12 23:19, Guido van Rossum wrote:
>>
>> 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())
>
>
> Not I was the first one who showed an example with f() and g(). ;) I only
> showed that it was wrong analogy.
>
> Yes, first of all I think about itertools.chain(). But then I found all
> other iterator tools which also can be extended to better generators
> support. Perhaps.
>
> I have only one imperfect example for use of StopIterator's value from
> generator (my patch for issue16009).
I don't understand that code at all, and it seems to be undocumented
(no docstrings, no mention in the external docs). Why is it using
StopIteration at all? There isn't an iterator or generator in sight.
AFAICT it should just use a different exception. But even if you did
use StopIteration -- why would you care about itertools here? AFAICT
it's just being used as a private communication channel between
scan_once() and its caller. Where is the possibility to wrap anything
in itertools at all?
> It is difficult to find examples for
> feature, which appeared only recently. But I think I can find them before
> 3.4 feature freezing.
I think you're going at this from the wrong direction. You shouldn't
be using this feature in circumstances where you're at all likely to
run into this "problem".
>> 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.>
>
> Indeed. But they work with subset of generators, and this subset can be
> extended. Please look at http://bugs.python.org/issue16150 (Implement
> generator interface in itertools.chain). Does it make sense?
But that just seems to perpetuate the idea that you have, which IMO is
wrongheaded. Itertools is for iterators, and all the extra generator
features make no sense for it.
--
--Guido van Rossum (python.org/~guido)
More information about the Python-ideas
mailing list