[Python-Dev] PEP Idea: Syntactic sugar for StopIteration.

Raymond Hettinger python at rcn.com
Sun Dec 9 00:42:11 CET 2007

> 2007/12/8, Raymond Hettinger <python at rcn.com>:
>>...the proposal adds new syntax without adding functionality.
> That is indeed the definition of syntactic sugar [1]. Python is full
> of that, for example the import statement.
 . . .
> The real problem is that
> raising StopIteration is not orthogonal. It is confusing for the
> reasons I exposed. Generators are something in the middle between a
> language feature and a framework/library. With 'yield break' they will
> be completely a language feature.

This personal notion of purity carries almost zero weight and is more a matter of personal taste/style than anything else. It 
certainly does not warrant a change to the grammar.

I've been a big fan of generators and tend to use them everywhere. I've *never* had a use case for "yield break" and find it 
uncommon to even "raise StopIteration".

The tone of your messages suggests that you're going to stick to this idea like glue, so to avoid further time wasting, this will 
likely be my last post on the subject.

If for some reason, you persist through to writing a PEP, it will be almost mandatory to scan existing, published code to find 
examples of code fragments that would be improved by 'yield break' .  My bet is that the examples will be rare and any "improvement" 
will be marginal at best and simply a matter of taste at worst.


More information about the Python-Dev mailing list