[Python-ideas] Revised revised revised PEP on yield-from
charlie137 at gmail.com
Tue Feb 17 04:05:09 CET 2009
I think we can already create coroutines and lightweight tasks already
without the need of the "yield from" syntax. The trick is to assume
that when a coroutine yields an other coroutine, the behaviour is the
same as using "yield from".
The code somehow looks like this :
# This is the actual coroutine we want to write
yield func2() # just like 'yield from func2()'
yield 10 # That would be the return value in a coroutine
# This is the code -probably wrong, and missing many things, but that
gives the idea- of the coroutine library
self.generator = generator
for value in self.generator:
if not isinstance(value, Coroutine):
# XXX: should also do all the proper checking as 'yield from' do
for subvalue in value.run():
The proposal could make things faster, and also slightly more coherent.
But what I don't really like with it, is that when you start to write
coroutines, you have to use yield every time you call an other
coroutine, and it make the code full of yield statement ; the proposal
if adopted would make it even worst.
More information about the Python-ideas