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. | [EMAIL PROTECTED] +--------------------------------------+ _______________________________________________ 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