On Mon, Oct 15, 2012 at 9:48 AM, Nick Coghlan email@example.com wrote:
On Mon, Oct 15, 2012 at 10:31 PM, Calvin Spealman firstname.lastname@example.org 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
-- Nick Coghlan | email@example.com | Brisbane, Australia