[Python-Dev] PEP 380 (yield from a subgenerator) comments
Steve Holden
steve at holdenweb.com
Fri Mar 27 08:21:44 CET 2009
Greg Ewing wrote:
> Guido van Rossum wrote:
>
>> That +0 could turn into a +1 if there was a way to flag this as an
>> error (at runtime), at least if the return is actually executed:
>>
>> def g():
>> yield 42
>> return 43
>>
>> for x in g():
>> print x # probably expected to print 42 and then 43
>>
>> Perhaps the exception used in this case could be a different exception
>> than StopIteration?
>
> Would checking that the value is None be sufficient? Or do you
> want to distinguish between 'return' and 'return None'? That
> would feel rather strange to me.
>
> I'm inclined to regard this as an unnecessary complication.
> People are already trained to think of 'return' and 'yield'
> as quite different things. I don't know why they would suddenly
> start using 'return' when they mean 'yield'.
>
Probably because they just started to use Python and they just don't
understand WT* you are talking about. Reviewing this thread reminds me
of the story about the Princeton math professor who started his lecture
by writing a complex three-line formula on the blackboard and saying
"From this it is obvious that ..." and then proceeded to gaze at the
blackboard in silence for three minutes. He then left the lecture
theater, somewhat to his students' consternation, only to reappear with
a smile on his face in ten minutes to say "Yes, it *is* obvious that ...".
I am a *bit* concerned, without really being able to put my finger on
it, that the "yield from" expression's value comes from inside (the
"return" from the nested generator) while the "yield from" expression's
value comes from "outside" (the value passed to a .send() method call).
Please forgive this bear of very little brain. I suspect the
documentation will need to make this asymmetry more obvious still.
regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Want to know? Come to PyCon - soon! http://us.pycon.org/
More information about the Python-Dev
mailing list