[Python-Dev] PEP 342 suggestion: start(), __call__() and unwind_call() methods
Greg Ewing
greg.ewing at canterbury.ac.nz
Mon Oct 10 04:43:31 CEST 2005
Guido van Rossum wrote:
> Plus, Piet also remarked that the value is silently ignored
> when the generator is used in a for-loop. ... I'd worry that accepting
> "return X" would increase the occurrence of bugs caused by someone
> habitually writing "return X" where they meant "yield X".
Then have for-loops raise an exception if they get a
StopIteration with something other than None as an
argument.
> I'd like to keep StopIteration really lightweight so it doesn't slow
> down its use in other places.
You could leave StopIteration itself alone altogether
and have a subclass StopIterationWithValue for returning
things. This would make the for-loop situation even safer,
since then you could distinguish between falling off the
end of a generator and executing 'return None' inside it.
--
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury, | A citizen of NewZealandCorp, a |
Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. |
greg.ewing at canterbury.ac.nz +--------------------------------------+
More information about the Python-Dev
mailing list