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

[ENH] PEP-654 Exception Groups and except* #4993

Open
da-woods opened this issue Aug 21, 2022 · 2 comments · May be fixed by #5482
Open

[ENH] PEP-654 Exception Groups and except* #4993

da-woods opened this issue Aug 21, 2022 · 2 comments · May be fixed by #5482

Comments

@da-woods
Copy link
Contributor

da-woods commented Aug 21, 2022

Is your feature request related to a problem? Please describe.

PEP-654 proposes a new "exception groups" feature, and a new except* syntax to implement it. This will come with Python 3.11 (so Cython probably shouldn't try to implement it until Python 3.11 is released just in case there are any changes).

See https://peps.python.org/pep-0654/.

Additional context

I don't understand this feature at all right now and wasn't planning to implement it myself...

@h-vetinari
Copy link
Contributor

h-vetinari commented Aug 23, 2022

I don't understand this feature at all right now

I'm sure you're exaggerating, but maybe the following helps. The whole feature is designed around helping deal with multiple exceptions being raised concurrently1 within a given block of code (e.g. several threads, or async, or ...).

To correctly reflect this, there needs to be something exception-like - i.e. can be caught/handled/rethrown - that can hold multiple individual exceptions (trio originally called this MultiError, cpython now chose ExceptionGroup), and the whole try:/except: game now needs to be able to deal with these containers, with some new additional operations (mainly filtering) due to now having (potentially) several different exceptions in one group.

In order not to break existing code through subtly different exception semantics between single exceptions and ExceptionGroups, this needed new syntax (except*) to distinguish intent2. There's more details regarding serialization, stacks, tracing, etc., but that's it.

Footnotes

  1. obviously those exceptions will not happen at the exact same instant in time, but from the point of view of the parent thread/nursery, when all the threads return control, several exceptions might have happened.

  2. If except SomeException had been empowered to filter SomeException out of ExceptionGroups that contain one, there could be cases that behave differently than before.

@da-woods
Copy link
Contributor Author

I'm sure you're exaggerating, [...]

I'm really not. But to be fair, I haven't done a lot with concurrency, and I also haven't spent any time trying to understand it yet.

[...] but maybe the following helps

Thanks - it's a very useful quick summary.

@da-woods da-woods self-assigned this May 28, 2023
@da-woods da-woods linked a pull request Jun 10, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants