[Async-sig] A possible tiny step towards event loop interoperability

Ben Darnell ben at bendarnell.com
Fri Jun 3 21:16:40 EDT 2016


On Fri, Jun 3, 2016 at 9:14 PM, Nathaniel Smith <njs at pobox.com> wrote:

> On Fri, Jun 3, 2016 at 6:10 PM, Ben Darnell <ben at bendarnell.com> wrote:
> > The introduction of `await` has imposed similar restrictions on both
> > systems, so there is no more yielding of lists or dicts in either case;
> > explicit wrapper objects must be used. (but there's still a difference in
> > that asyncio.Task allows None but tornado coroutines do not)
>
> I'm not saying that yielding lists or dicts is useful, but it sounds
> like you're saying that somehow it's actually incompatible with
> async/await, and I don't understand why that would be -- e.g., this
> works fine?:
>

Yes, this works fine as long as you have the extra hop into a decorated
coroutine. What you can't do is `await [1, 2, 3]` in an `async def` native
coroutine.


>
> In [2]: @types.coroutine
>    ...: def yield_list():
>    ...:     yield [1, 2, 3]
>    ...:
>
> In [3]: async def f():
>    ...:     await yield_list()
>    ...:
>
> In [4]: next(f().__await__())
> Out[4]: [1, 2, 3]
>
> -n
>
> --
> Nathaniel J. Smith -- https://vorpus.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/async-sig/attachments/20160603/962d78d2/attachment.html>


More information about the Async-sig mailing list