[Python-Dev] Return from generators in Python 3.2 (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Fri Aug 27 00:11:46 CEST 2010
- Previous message: [Python-Dev] Return from generators in Python 3.2
- Next message: [Python-Dev] Return from generators in Python 3.2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, Aug 27, 2010 at 1:00 AM, Yury Selivanov <yselivanov at 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 | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] Return from generators in Python 3.2
- Next message: [Python-Dev] Return from generators in Python 3.2
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]