[Python-ideas] x=(yield from) confusion [was:Yet another alternative name for yield-from]
greg.ewing at canterbury.ac.nz
Mon Apr 6 01:38:30 CEST 2009
Jacob Holm wrote:
> The argument that we have no value to send before we have yielded is
> wrong. The generator containing the "yield-from" could easily have a
> value to send (or throw)
No, Guido is right here. You *can't* send a value (other
than None) into a generator that hasn't reached its first
yield (try it and you'll get an exception). The first
call has to be next().
> and if iter(EXPR) returns a coroutine or a
> non-generator it could easily be ready to accept it.
If it's ready to accept a send, it must have already
yielded a value, which has been lost, when it should have
been yielded to the caller of the delegating generator.
> In an earlier thread we concluded that if
> the thrown exception is a StopIteration and the *same* StopIteration
> instance escapes the throw() call, it should be reraised rather than
> caught and turned into a RETVAL.
That part is right.
> Next issue is that the value returned by it.close() is thrown away by
Since I don't believe that close() should be expected to
return a useful value anyway, that's not a problem.
More information about the Python-ideas