Skip to content
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

Closed
1st1 opened this issue Jul 23, 2015 · 8 comments
Closed

Add CoroutineReturn and CoroutineExit builtin exceptions for coroutines #68885

1st1 opened this issue Jul 23, 2015 · 8 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@1st1
Copy link
Member

1st1 commented Jul 23, 2015

BPO 24697
Nosy @gvanrossum, @ncoghlan, @scoder, @1st1

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:

assignee = 'https://github.com/1st1'
closed_at = <Date 2016-10-05.23:48:17.715>
created_at = <Date 2015-07-23.15:10:15.634>
labels = ['interpreter-core', 'type-feature']
title = 'Add CoroutineReturn and CoroutineExit builtin exceptions for coroutines'
updated_at = <Date 2016-10-05.23:48:17.713>
user = 'https://github.com/1st1'

bugs.python.org fields:

activity = <Date 2016-10-05.23:48:17.713>
actor = 'yselivanov'
assignee = 'yselivanov'
closed = True
closed_date = <Date 2016-10-05.23:48:17.715>
closer = 'yselivanov'
components = ['Interpreter Core']
creation = <Date 2015-07-23.15:10:15.634>
creator = 'yselivanov'
dependencies = []
files = []
hgrepos = []
issue_num = 24697
keywords = []
message_count = 8.0
messages = ['247214', '247217', '247218', '247227', '247229', '247230', '247263', '278164']
nosy_count = 4.0
nosy_names = ['gvanrossum', 'ncoghlan', 'scoder', 'yselivanov']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue24697'
versions = ['Python 3.6']

@1st1
Copy link
Member Author

1st1 commented Jul 23, 2015

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:

  1. Add CoroutineReturn exception type, inherited from StopIteration;

  2. Add CoroutineExit exception type, inherited from GeneratorExit.

@1st1 1st1 self-assigned this Jul 23, 2015
@1st1 1st1 added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Jul 23, 2015
@gvanrossum
Copy link
Member

What problem does this solve?

1 similar comment
@gvanrossum
Copy link
Member

What problem does this solve?

@1st1
Copy link
Member Author

1st1 commented Jul 23, 2015

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.

@gvanrossum
Copy link
Member

Hm, I think there's little need for new exceptions...

@scoder
Copy link
Contributor

scoder commented Jul 23, 2015

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.

@ncoghlan
Copy link
Contributor

My initial inclination is to agree with Stefan. At the moment, we have a
slightly leaky abstraction where the exceptions used mean that coroutines
still expose the fact that under the covers they're defined in terms of
generator semantics.

However, that leak in the abstraction reveals an underlying truth -
coroutine semantics *are* derived from generator semantics, and they *do*
share common underlying infrastructure.

We may eventually find pragmatic reasons for wanting to plug that leak and
use separately named exceptions, but unlike the situation with coroutines
themselves, I'm not currently seeing a clear gain in either usability or
comprehensibility as a payoff for the extra complexity.

@1st1
Copy link
Member Author

1st1 commented Oct 5, 2016

Closing this one. Seems we can live just fine without these new exceptions.

@1st1 1st1 closed this as completed Oct 5, 2016
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants