There are essentially two alternatives: yield a magic value, or raise a magic exception. I don't like yield, because it overloads the other semantic of yield, which are already so severely overloaded. So I prefer the magic exception. To raise an exception, you can either use a raise statement with a special exception, or a special function that raises it. The semantics are the same. I prefer the raise statement, because it makes it clear that control flows out of the function here (and any code following it is dead). Also, Emacs automatically dedents after a raise statement, which is what you want. Finally, in Python 3.3+, return from a generator is actually implemented by raising StopIteration with the return value as argument. So it's semantically very close.
On Tue, Jan 7, 2014 at 4:37 AM, Tobias Oberstein <[email protected]> wrote: >> * Trollius coroutines must use "raise Return(value)", whereas Tulip >> simply > > > Could you explain why that particular construct of "returning by raising" > was chosen? > > It works, but looks strange .. > > https://github.com/tavendo/AutobahnPython/blob/master/examples/asyncio/websocket/slowsquare/server_py2.py#L34 > > /Tobias -- --Guido van Rossum (python.org/~guido)
