I would prefer plain 'yield' to 'yield break' as a synonym for 'raise 
StopIteration'.
But the raise stands out better visually as an exit point.

The point about the raise not being explicitly caught is not valid since 
any generator could be used in the following code

g = some_gen
try:
    while True:
        process(g.next())
except StopIteration:
    whatever()

where it is caught.  Then under your proposal, there would be a catch 
without a throw ;-(.

If there were a use case for empty generators, then iter() could be made to 
produce one, in analogy with int() returning 0, etc.  But without a use 
case, 'iter()' is much more likely to be a bug and should be flagged as 
such.  In the meanwhile, 'iter(())' is trivial to type.

Terry Jan Reedy



_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to