Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Terry Reedy
On 11/27/2017 5:05 PM, Guido van Rossum wrote: On Mon, Nov 27, 2017 at 1:58 PM, Greg Ewing > wrote: Guido van Rossum wrote: The source for sleep() isn't very helpful -- e.g. @coroutine is mostly a backwards compatibility thing. So how

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Guido van Rossum
On Mon, Nov 27, 2017 at 1:58 PM, Greg Ewing wrote: > Guido van Rossum wrote: > >> The source for sleep() isn't very helpful -- e.g. @coroutine is mostly a >> backwards compatibility thing. >> > > So how are you supposed to write that *without* using @coroutine? > A simplified version using async

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Greg Ewing
Guido van Rossum wrote: The source for sleep() isn't very helpful -- e.g. @coroutine is mostly a backwards compatibility thing. So how are you supposed to write that *without* using @coroutine? -- Greg ___ Python-Dev mailing list Python-Dev@python.o

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Guido van Rossum
On Sun, Nov 26, 2017 at 7:43 PM, Chris Angelico wrote: > Honestly, this is one of Python's biggest problems when it comes to > async functions. I don't know the answer to that question, and I don't > know where in the docs I'd go looking for it. In JavaScript, async > functions are built on top o

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Guido van Rossum
On Mon, Nov 27, 2017 at 1:12 AM, Antoine Pitrou wrote: > On Mon, 27 Nov 2017 00:41:55 -0800 > Nathaniel Smith wrote: > > > > Since most libraries assume that they control both __await__ and the > > coroutine runner, they don't tend to give great error messages here > > (though trio does [2] ;-))

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Caleb Hattingh
On 27 November 2017 at 18:41, Nathaniel Smith wrote: > > In asyncio, the convention is that the values you send back must be > Future objects, Thanks this is useful. I didn't pick this up from the various PEPs or documentation. I guess I need to go through the src :) ___

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Paul Sokolovsky
Hello, On Mon, 27 Nov 2017 15:33:51 +1000 Caleb Hattingh wrote: [] > The PEP only says that __await__ must return an iterator, but it > turns out that it's also required that that iterator > should not return any intermediate values. This requirement is only > enforced in the event loop, not >

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Antoine Pitrou
On Mon, 27 Nov 2017 00:41:55 -0800 Nathaniel Smith wrote: > > Since most libraries assume that they control both __await__ and the > coroutine runner, they don't tend to give great error messages here > (though trio does [2] ;-)). I think this is also why the asyncio docs > don't talk about this.

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-27 Thread Nathaniel Smith
On Sun, Nov 26, 2017 at 9:33 PM, Caleb Hattingh wrote: > The PEP only says that __await__ must return an iterator, but it turns out > that it's also required that that iterator > should not return any intermediate values. I think you're confused :-). When the iterator yields an intermediate value

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-26 Thread Caleb Hattingh
On 27 November 2017 at 14:53, Yury Selivanov wrote: > It is correct. While 'yield from coro()', where 'coro()' is an 'async > def' coroutine would make sense in some contexts, it would require > coroutines to implement the iteration protocol. That would mean that > you could write 'for x in cor

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-26 Thread Yury Selivanov
On Sun, Nov 26, 2017 at 11:23 PM, Caleb Hattingh wrote: [..] > I'd be very grateful if anyone can point out if my understanding of the > above is incorrect. Private email is fine if you prefer not to post to the > list. It is correct. While 'yield from coro()', where 'coro()' is an 'async def'

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-26 Thread Caleb Hattingh
On 27 November 2017 at 13:20, David Mertz wrote: > > Imagining that 'yield' vanished from the language tomorrow, and I wanted > to write the same thing with async/await, I think the best I can come up > with is... actually, I just don't know who to do it without any `yield`. > I recently had to l

Re: [Python-Dev] Using async/await in place of yield expression

2017-11-26 Thread Chris Angelico
On Mon, Nov 27, 2017 at 2:20 PM, David Mertz wrote: > Changing subject line because this is way off to the side. Guido and > Nathaniel point out that you can do everything yield expressions do with > async/await *without* an explicit event loop. While I know that is true, it > feels like the bes

[Python-Dev] Using async/await in place of yield expression

2017-11-26 Thread David Mertz
Changing subject line because this is way off to the side. Guido and Nathaniel point out that you can do everything yield expressions do with async/await *without* an explicit event loop. While I know that is true, it feels like the best case is adding fairly considerable ugliness to the code in