[Python-ideas] Propagating StopIteration value

Mike Graham mikegraham at gmail.com
Sun Oct 7 22:27:48 CEST 2012


On Sun, Oct 7, 2012 at 3:06 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> On 07.10.12 05:11, Greg Ewing wrote:
>>
>> It's highly debatable whether this is even wrong. The purpose
>> of StopIteration(value) is for a generator to return a value
>> to its immediate caller when invoked using yield-from. The
>> value is not intended to propagate any further than that.
>
>
> If immediate caller can propagate generated values with the help of "yield
> from", why it can not propagate returned from "yield from" value?
>
>
>> A non-iterator analogy would be
>>
>>     def f():
>>        return 42
>>
>>     def g():
>>        f()
>
>
> No, a non-iterator analogy would be
>
>   g = functools.partial(f)
>
> or
>
>   g = functools.lru_cache()(f)
>
> I expect g() to return 42 here.

Rather than speaking in analogies, can we be concrete? I can't imagine
doing map(f, x) where x is a generator whose return value I cared
about. Can you show us a concrete example of something that looks like
practical code?

Mike



More information about the Python-ideas mailing list