Please comment on Draft PEP for Enhanced Generators
othello at javanet.com
Wed Jan 30 19:21:58 CET 2002
"Pete Shinners" <pete at shinners.org> wrote in message
news:3C583334.9050306 at shinners.org...
> Raymond Hettinger wrote:
> > I have written a draft PEP summarizing proposed enhancements to
> > http://users.javanet.com/~othello/download/genpep.htm
> > The draft reflects all the comments I've received to date on the threads
> > where
> > the ideas where first proposed.
> > Please post your comments (and maybe a little encouragment) here on
> > comp.lang.py or email them directly to me.
> i have one small request for generators. it may actually be a bad idea
> but i sure can't guess why it would be. perhaps it can be added to your
> PEP if it is going to get implemented. it sure looks good to me, so i
> hope it does get implented.
> anyways, i would like the be able to simply call "yield" with no
> arguments and have it yield None. basically the same as the "return"
> keyword works.
In my experiments with yield, I bumped into the same thing -- many
instances of yield None. I made a proposal similar to yours
on comp.lang.python and got convincing replies that it should NOT be
In a nutshell, they argued that yield without an argument is typically
a bug, not an intentional yield None. There was an appeal to 'explicit
is better than implicit' and a comment that if they had it to do over
again, they never would have allowed return to have an implicit None.
Surprisingly, I also got comments that the odds of this being considered
less than zero. Not being conversant with negative probabilities, I
and withdrew the suggestion.
> i want to use generators like little mini-threads, and really don't care
> about what it really yields. in my current tests i've just done "yield
> 0" or "yield None", but i think the code would be clearer if i just
> could say "yield".
> interesting ideas on the 'two way yield'. i'm curious to see what comes
> of that :]
Since you've encountered yield None, it's clear that you're already on the
path to realizing that yield is more than an easy way to create an iterator.
It does something truly magical by suspending execution and saving
state. It has the potential to do a lot more than its original purpose.
More information about the Python-list