[Python-Dev] async/await in Python; v2
Greg Ewing
greg.ewing at canterbury.ac.nz
Thu Apr 23 09:36:23 CEST 2015
Victor Stinner wrote:
> A huge part of the asyncio module is based on "yield from fut" where fut is
> a Future object.
>
> How do you write this using the PEP 3152? Do you need to call an artifical
> method like "cocall fut.return_self()" where the return_self() method simply
> returns fut?
In a PEP 3152 world, Future objects and the like would be
expected to implement __cocall__, just as in a PEP 492 world
they would be expected to implement __await__.
> @asyncio.coroutine currently calls a function and *then* check if it should
> yields from it or not:
>
> res = func(*args, **kw)
> if isinstance(res, futures.Future) or inspect.isgenerator(res):
> res = yield from res
To accommodate the possibility of func being a cofunction,
you would need to add something like
if is_cofunction(func):
res = yield from costart(func, *args, **kw)
else:
# as above
--
Greg
More information about the Python-Dev
mailing list