On Fri, Nov 25, 2016 at 12:03 AM, Alex Grönholm <alex.gronh...@nextday.fi> wrote: > 24.11.2016, 23:23, Nathaniel Smith kirjoitti: > > On Nov 23, 2016 11:29 PM, "Alex Grönholm" <alex.gronh...@nextday.fi> wrote: >> >> 23.11.2016, 01:34, Nathaniel Smith kirjoitti: >>> >>> On Tue, Nov 22, 2016 at 2:22 PM, Alex Grönholm <alex.gronh...@nextday.fi> >>> wrote: >>> > I'm not sure where asyncio_extras's async generator implementation >>> > assumes >>> > you're using asyncio. Could you elaborate on that? >>> >>> If I'm reading it right, it assumes that the only two things that might >>> be yielded to the coroutine runner are either (a) the special yield wrapper, >>> or (b) an awaitable object like an asyncio.Future. This works on asyncio, >>> because that's all the asyncio runner supports, but it doesn't work with >>> (for example) curio. async_generator (like native async generators) allows >>> arbitrary objects to be yielded to the coroutine runner. >> >> You are misreading the code. It is in no way limited to what asyncio >> accepts. It doesn't even import asyncio in the asyncyield or generator >> modules. The only parts of the library that depend on PEP 3156 event loops >> are the ones that involve executors and threads. > > I didn't say that it imported asyncio. I said that it assumes the only > things that will be yielded are the things that asyncio yields. This is the > line that I'm worried about: > > > https://github.com/agronholm/asyncio_extras/blob/aec412e1b7034ca3cad386c381e655ce3547fee3/asyncio_extras/asyncyield.py#L40 > > The code awaits the value yielded by the coroutine, but there's no guarantee > that this value is awaitable. It's an arbitrary Python object representing a > message sent to the coroutine runner. It turns out that asyncio only uses > awaitable objects for its messages, so this code can get away with this on > asyncio, but if you try using this code with curio then I'm pretty sure > you're going to end up doing something like "await (3,)" and then blowing > up. > > PEP 492 clearly states the following: > > It is a TypeError to pass anything other than an awaitable object to an > await expression. > > That (3,) is not an awaitable, so the example is invalid. That said, I will > re-examine this part of the implementation and correct it if necessary.
I feel like I'm running out of ideas for how to explain this, and starting to just repeat myself :-(. There is nothing that says the return value from coro.__next__() must be awaitable. Coroutines can yield arbitrary objects. (3,) is not awaitable, but it's a perfectly valid thing to be yielded from a coroutine. > So far I just haven't encountered anything that would produce an error. That's because you've only tested on asyncio, not curio. I promise! -n -- Nathaniel J. Smith -- https://vorpus.org _______________________________________________ Async-sig mailing list Async-sig@python.org https://mail.python.org/mailman/listinfo/async-sig Code of Conduct: https://www.python.org/psf/codeofconduct/