Hello, On Fri, 19 Feb 2021 06:29:35 -0300 Luciano Ramalho <luci...@ramalho.org> wrote:
> On Fri, Feb 19, 2021 at 4:08 AM Guido van Rossum <gu...@python.org> > wrote: > > Can you try this? > > > > async def __sleep(self): > > await None > > That didn't work*, but this does: > > async def __sleep(): > return None > > Was that the idea? No. That doesn't return control to the event loop, like the original "yield" does. The purpose of all these shaman dances to obfuscate the relationship between generators and async functions is unclear. (Well, it's kinda clear - to allow "async generators", but ughh, don't let me start on that.) The best solution now indeed appears to allow an "await None" special construct, to have the same meaning as "yield", but only for async functions. Any other solution is dirty (and inefficient!) workaround. > > (*) TypeError: object NoneType can't be used in 'await' expression > > > > > On Thu, Feb 18, 2021 at 22:31 Luciano Ramalho <luci...@ramalho.org> > > wrote: > >> > >> Follow up question: what's the plan to replace this use of > >> `@types.coroutine` in `asyncio/tasks.py`? [1] > >> > >> @types.coroutine > >> def __sleep0(): > >> """<docstring omitted>""" > >> yield > >> > >> [1] > >> https://github.com/python/cpython/blob/master/Lib/asyncio/tasks.py#L585 > >> > >> Best, > >> > >> Luciano > >> > >> On Fri, Feb 19, 2021 at 2:31 AM Luciano Ramalho > >> <luci...@ramalho.org> wrote: > >> > > >> > On Fri, Feb 19, 2021 at 1:59 AM Guido van Rossum > >> > <gu...@python.org> wrote: > >> > >> 1) What Python construct is to be used at the end of a chain > >> > >> of await calls, if not of a generator-based coroutine > >> > >> decorated with `@types.coroutine` and using a `yield` > >> > >> expression in its body? > >> > > >> > > At the end of the chain you can call the __await__() method > >> > > which gives an iterator, and then you call next() or send() on > >> > > that iterator. Each next()/send() call then represents an > >> > > await step, and send() in general is used to provide an > >> > > awaited result. Eventually this will raise StopIteration with > >> > > a value indicating the ultimate result (the return value of > >> > > the top-level async def). > >> > > >> > All right, that made sense to me. Thank you so much, Guido. > >> > > >> > Thanks for the clarification about `@types.coroutine` as well. > >> > > >> > Take care, > >> > > >> > Luciano > >> > > >> > > >> > -- > >> > Luciano Ramalho > >> > | Author of Fluent Python (O'Reilly, 2015) > >> > | http://shop.oreilly.com/product/0636920032519.do > >> > | Technical Principal at ThoughtWorks > >> > | Twitter: @ramalhoorg > >> > >> > >> > >> -- > >> Luciano Ramalho > >> | Author of Fluent Python (O'Reilly, 2015) > >> | http://shop.oreilly.com/product/0636920032519.do > >> | Technical Principal at ThoughtWorks > >> | Twitter: @ramalhoorg > > > > -- > > --Guido (mobile) > > > > -- > Luciano Ramalho > | Author of Fluent Python (O'Reilly, 2015) > | http://shop.oreilly.com/product/0636920032519.do > | Technical Principal at ThoughtWorks > | Twitter: @ramalhoorg > _______________________________________________ > Python-Dev mailing list -- python-dev@python.org > To unsubscribe send an email to python-dev-le...@python.org > https://mail.python.org/mailman3/lists/python-dev.python.org/ > Message archived at > https://mail.python.org/archives/list/python-dev@python.org/message/4YLGMUXFPWKHQOQI4SEOM4UR2EN5MUNN/ > Code of Conduct: http://python.org/psf/codeofconduct/ -- Best regards, Paul mailto:pmis...@gmail.com _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/EM6VKVKSIHZTYFKTMZL4NV6HCDQ45N3L/ Code of Conduct: http://python.org/psf/codeofconduct/