[Python-ideas] should there be a difference between generators and iterators?
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat Sep 6 04:20:38 CEST 2008
Bruce Frederiksen wrote:
> what is happening
> is that the 'finally' clause in a generator isn't being honored by 'for'
> statements.
It's not all that clear whether the for-loop should be
doing anything special to force a generator to finalize
if the loop is exited prematurely. The for-loop isn't
necessarily the only thing using the iterator -- other
code may want to carry on getting items from it, in
which case you *don't* want it forcibly terminated.
More generally, I'm a bit worried by all the extra
complications that generators seem to be accruing. If
it becomes a general expectation that an iterator based
on other iterators is supposed to pass on all these
special conditions, it's going to put a big burden on
implementors of iterators, and turn what ought to be
very simple and straightforward code into something
convoluted.
--
Greg
More information about the Python-ideas
mailing list