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

Antoine Pitrou solipsis at pitrou.net
Thu Feb 19 16:28:34 CET 2009


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

Regards

Antoine.





More information about the Python-ideas mailing list