On Fri, Aug 27, 2010 at 1:00 AM, Yury Selivanov <yseliva...@gmail.com> wrote:
> In the above, GeneratorReturn error will be propagated stopping the program 
> execution.
> Strictly speaking, the proposed change is just alters the current Python 
> behaviour,
> making the 'return value' statement raise catchable error (instead of 
> SyntaxError.)

There are fairly extensive discussions of using a new GeneratorReturn
exception rather than StopIteration in the python-dev archives. As I
recall, one key factor leading to the use of StopIteration was the
suggestion's implied breakage of the equivalence between "return"
(which would continue to raise StopIteration) and "return None" (which
would raise GeneratorReturn with a value of None). Using a different
exception also made all generator handling code clumsier, since it now
needed to deal with two exceptions rather than just one.

Since the only situations where a return value could be inadvertently
ignored were those where the application clearly didn't care about the
return value anyway, it was decided that sticking with a single
exception type was the better approach.

PEP 380 should probably mention this idea explicitly though, since
using a new exception type is a fairly obvious alternative suggestion
and the discussion of the idea is scattered all over the place in the
archives.

As for breaking the moratorium for it - no, not even close to a big
enough win, since people can already write "raise
CoroutineReturn(result)".

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to