You got it exactly right. Regarding  what's more important
(performance or debuggability) or what's more readable, it's
completely up to you. :-)

On Sat, Jan 4, 2014 at 7:05 AM, Jonathan Slenders
<[email protected]> wrote:
>
> 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



-- 
--Guido van Rossum (python.org/~guido)

Reply via email to