[Python-Dev] PEP 342 suggestion: start(), call() and unwind_call() methods (original) (raw)
Greg Ewing greg.ewing at canterbury.ac.nz
Mon Oct 10 04:43:31 CEST 2005
- Previous message: [Python-Dev] New PEP 342 suggestion: result() and allow "return with arguments" in generators (was Re: PEP 342 suggestion: start(), __call__() and unwind_call() methods)
- Next message: [Python-Dev] PEP 342 suggestion: start(), __call__() and unwind_call() methods
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 +--------------------------------------+
- Previous message: [Python-Dev] New PEP 342 suggestion: result() and allow "return with arguments" in generators (was Re: PEP 342 suggestion: start(), __call__() and unwind_call() methods)
- Next message: [Python-Dev] PEP 342 suggestion: start(), __call__() and unwind_call() methods
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]