Yury Selivanov wrote:
However, as I outlined in the first message, this was intended to prevent this kind of mistakes:
... def test(): ... for i in range(10): ... yield i ... return 10
Which will certainly happen, especially with people new to python.
That very problem was considered in the discussion, and it was concluded that it wasn't severe enough to be worth breaking the symmetry between return <-> StopIteration and return value <-> StopIteration(value).
Good point. It's all about our level of care about beginners ;)
While due consideration is always given to beginners, being beginner-friendly is not a good enough reason to introduce a feature that would be *unfriendly* to experienced programmers.
I, for example, deal with really a lot of coroutine based code, and it's very annoying that I have to use some creepy abstractions in order to just return a value!
Even with your proposal, you'd still have to use a 'creepy abstraction' every time one of your coroutines calls another. That's why PEP 380 deals with 'more than just return'. -- Greg