PEP-380 introduces the yield from
syntax and says:
yield from <expr>
where is an expression evaluating to an iterable, from which an iterator is extracted. So the following are legal and make sense:
- yield from generators
- yield from generator_based_coroutine ( that use the
@asyncio.coroutine
decorator)
since both generators and generator based coroutines are instances of Iterable. However, I fail to understand why
yield from native_coroutines (using async/await syntax)
is legal? Since PEP-492 states that native coroutines don't implement the __iter__
and __next__
methods and therefore aren't iterable. However, there's no PEP that talks about this change in behavior of yield from to accept coroutine objects that are returned by native coroutines?
I know generator based coroutines will get deprecated in 3.10 but I still want to know why yield from
works with native coroutines.