[Python-ideas] The async API of the future: yield-from

Calvin Spealman ironfroggy at gmail.com
Mon Oct 15 16:16:14 CEST 2012

On Mon, Oct 15, 2012 at 9:48 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> On Mon, Oct 15, 2012 at 10:31 PM, Calvin Spealman <ironfroggy at gmail.com> wrote:
>> Currently, "with yield expr:" is not valid syntax, surprisingly.
> It's not that surprising, it's the general requirement that yield
> expressions must be enclosed in parentheses except when used
> standalone or in a simple assignment statement.
> "with (yield expr):" is valid syntax though, so I'm reluctant to
> endorse doing anything substantially different if the parentheses are
> omitted.

Silly oversight on my part, and I agree that the parens shouldn't make the
difference in meaning.

> I think the combination of "yield from" to delegate control (including
> exception handling) completely to a subgenerator and "context manager
> + for loop + explicit yield" when an operation needs to yield multiple
> times and the exception handling behaviour should be left to the
> caller (as in the "as_completed" case) should cover the necessary
> behaviours.

I'm still -1 on delegating control to subgenerators with yield-from,
versus having the scheduler just deal with them directly.  I think it
is far less flexible.

I would still like to see a less confusing "with yield expr:" by
simply allowing it without parens, but no special meaning. I think it
would be really useful in coroutines.

with yield collect() as tasks:
  yield task1()
  yield task2()
results = yield tasks

> Cheers,
> Nick.
> --
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

Read my blog! I depend on your acceptance of my opinion! I am interesting!
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

More information about the Python-ideas mailing list