[Python-ideas] Revised^4 PEP on yield-from

Guido van Rossum guido at python.org
Thu Feb 19 17:08:08 CET 2009


On Thu, Feb 19, 2009 at 7:28 AM, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Greg Ewing <greg.ewing at ...> writes:
>>
>> Use of StopIteration to return values
>> -------------------------------------
>
> Why not a dedicated exception (e.g. GeneratorReturn) instead?
> Two advantages to doing so:
> * people mistakingly doing a "for" loop over such a generator would be
>  reminded that they are missing something (the return value)
> * you could take advantage of existing iterator-consuming features (e.g.
>  "yield from map(str, innergenerator())"), since they would just forward
>  the exception instead of silencing it

Seconded -- but I would make it inherit from StopIteration so that the
for-loop (unless modified) would just ignore it.

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-ideas mailing list