[Python-ideas] Yield-from: Nonexistent throw() and close()?

Bruce Frederiksen dangyogi at gmail.com
Sat Feb 21 14:47:36 CET 2009


Jacob Holm wrote:
> Greg Ewing wrote:
>> I'm happy to raise exceptions in the face of nonexistent
>> send() methods, but I'm not so sure about throw() and
>> close().
> I'm not.  I'd hate for this:
>
> def foo():
>    for i in xrange(5):
>        yield i
>
> to behave different from this:
>
> def foo():
>    yield from xrange(5)
These two forms already behave differently when generators are used 
(rather than xrange), why should they not also behave differently when 
non-generators are used?

"In the face of ambiguity, refuse the temptation to guess."

I think that an exception makes more sense, otherwise, we are guessing 
as to what the programmer intended by using send in your example.



More information about the Python-ideas mailing list