Andy Wingo wrote:
close() does not seem to have much value given that it isn't part of the
iterators specification, and one can do any needed action by doing a
throw() on the iterator and relying on the generator to have a finally
block if needed.

But throwing has other unwanted effects, in general. First, you need to define a generator and give it a name. Then, close callers need to throw that exception. For this reason, Python defined a built-in exception, GeneratorExit.

But when we prototyped generators (ES4 days), with Python 2.5 already done and a good source of design experience to draw from, Igor Bukanov and I came to the current design that forces a return. A forced return runs the finallys but of course not catches, and it relieves everyone from a built-in exception. We killed StopIteration, it would be bad to add GeneratorExit back.

Igor even took the forced-return solution to python-dev and got a blessing from Philip J. Eby, as a better solution than GeneratorExit.

/be
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to