New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add CoroutineReturn and CoroutineExit builtin exceptions for coroutines #68885
Comments
Since native coroutines (see PEP-492) hadn't had a separate type when the PEP was accepted, we didn't discuss that it might be necessary to introduce new exception types specifically for coroutines. To maintain backwards compatibility with 3.5, I think we can do the following:
|
What problem does this solve? |
1 similar comment
What problem does this solve? |
Only avoiding confusion, because coroutines now have a separate type, lack __iter__, and thus are quite different (on the surface) from generators. The fact that 'coro.send(..)' raises StopIteration (when coroutines aren't iterable), and that 'coro.close()' raises GeneratorExit might be confusing and non-obvious to some users. FWIW I created this ticket mostly as a reminder for myself to have some discussion on this topic in the future, when 3.5 is released and we have some initial feedback on PEP-492 ideas. |
Hm, I think there's little need for new exceptions... |
While I agree with Yuri that the names are a bit awkward, I actually second this. The StopIteration is almost an implementation detail of how the return value is passed on to become the (Future) result of the coroutine. It is intended to be caught by some framework and users would not normally get to see that exception. There is little room for general confusion. |
My initial inclination is to agree with Stefan. At the moment, we have a However, that leak in the abstraction reveals an underlying truth - We may eventually find pragmatic reasons for wanting to plug that leak and |
Closing this one. Seems we can live just fine without these new exceptions. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: