Hi all,

Something I was wondering.
If anyone can confirm my reasoning. Let's take the following code:

@coroutine
def a():
   result = yield from b()
   return result

This will make sure that if an exception is raised inside 'b', we will see 
'a' on the stack. Now we could also rewrite the code as follows:

def a():
   return b()

Now 'a' returns the generator created by 'b'. But if an exception occurs 
inside 'b', you won't see 'a' on stack, only the caller of 'a'. I suppose 
that this performs better, because there is one frame less for the future 
objects to be passed through (is that correct?), but it can make debugging 
harder, because the function called by "yield from" is not always the 
function that was called, it can also be another generator returned by that 
function.

What are the best practices. Should or shouldn't we do this? If we have to, 
do we consider the following readable?

@coroutine
def a():
    return (yield from b())


Cheers,
Jonathan

Reply via email to