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 +--------------------------------------+
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4