Am 07.01.2014 16:55, schrieb Guido van Rossum:
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

Not sure I fully get it:

Twisted's `inlineCallback` use regular raise for exceptions, but a special `returnValue` function for returning

https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/websocket/slowsquare/server.py#L36

Is that a third alternative? [not a rhetorical question! ;)]

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.

That's very interesting. Need to think more about it ..

Thanks for this detailed explanation!

/Tobias


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




Reply via email to