On Oct 8, 2005, at 9:10 PM, Nick Coghlan wrote: > So, instead of having "return" automatically map to "raise > StopIteration" > inside generators, I'd like to suggest we keep it illegal to use > "return" > inside a generator
Only one issue with that: it's _not currently illegal_ to use return inside a generator. From the view of the outsider, it currently effectively does currently map to "raise StopIteration". But not on the inside, just like you'd expect to happen. The only proposed change to the semantics is to also allow a value to be provided with the return. > def generator(): > yield > try: > return > except StopIteration: > print "But we would get here!" >>> def generator(): ... yield 5 ... try: ... return ... except StopIteration: ... print "But we would get here!" ... >>> x=generator() >>> x.next() 5 >>> x.next() Traceback (most recent call last): File "<stdin>", line 1, in ? StopIteration >>> James _______________________________________________ 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