Uh oh!
There was an error while loading. Please reload this page.
gh-99553: add tests for ExceptionGroup wrapping - #99615
Conversation
8158778 to
4b9e01aComparesobolevn
commented
Nov 20, 2022
@Zac-HD I cannot do that, but if you change you PR title from |
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
| A subclass of :exc:`BaseExceptionGroup` that extends :exc:`Exception` | ||
| cannot wrap :exc:`BaseException`\ s, as is the case with :exc:`ExceptionGroup`. | ||
| However, there is no further restriction: a :exc:`BaseExceptionGroup` subclass | ||
| which extends :exc:`KeyError` could wrap any :exc:`Exception`. |
There was a problem hiding this comment.
I think this is a strange thing to say in a doc, because why would you expect it to not wrap any Exception?
Maybe instead of the second sentence we could just explain the motivation for the restriction: “This ensures that wrapped BaseExceptions are not caught by ‘except Exception’.”
There was a problem hiding this comment.
why would you expect it to not wrap any Exception?
Suppose we have class MyEG(BaseExceptionGroup, X):, where except X: will catch such a group because it extends X. We disallow wrapping BaseExceptions in an ExceptionGroupbecause they would not be caught by except Exception: if unwrapped.
However this logic is not applied consistently: if X is e.g. KeyError, then except KeyError: can indeed catch MyEG("", [ValueError()]). I find this inconsistency surprising, which is why I commented on #99572 and then opened this PR!
(I'm not trying to reopen the design discussion, just trying to explain my perspective)
There was a problem hiding this comment.
Ok, I see. Well yes, the Exception case is different - people use ‘expect Exception’ as ‘catch everything except fatal errors’.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Zac-HD
commented
Nov 29, 2022
Ready to merge, I think? |
| A subclass of :exc:`BaseExceptionGroup` that extends :exc:`Exception` | ||
| cannot wrap :exc:`BaseException`\ s, as is the case with :exc:`ExceptionGroup`. | ||
| However, there is no further restriction: a :exc:`BaseExceptionGroup` subclass | ||
| which extends :exc:`KeyError` could wrap any :exc:`Exception`. |
There was a problem hiding this comment.
I don't think this comment is easy to understand without the justification. How about this?
| A subclass of :exc:`BaseExceptionGroup` that extends :exc:`Exception` | |
| cannot wrap:exc:`BaseException`\ s, as is the case with :exc:`ExceptionGroup`. | |
| However, there is no further restriction: a :exc:`BaseExceptionGroup` subclass | |
| which extends :exc:`KeyError` could wrap any :exc:`Exception`. | |
| Like :exc:`ExceptionGroup`, user-defined subclasses of :exc:`BaseExceptionGroup` | |
| that extend:exc:`Exception` can only wrap :exc:`Exception` subclasses. | |
| This is to prevent exceptions that represent fatal errors from being wrapped in an | |
| exception group which can be caught by ``except Exception``. See also :ref:`exceptions`. |
kumaraditya303
left a comment
There was a problem hiding this comment.
Please address Irit's review.
bedevere-bot
commented
Jan 1, 2023
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Zac-HD
commented
Apr 11, 2023
I've taken a few attempts, and haven't found a way to explain this which reliably clarifies rather than confuses, so I'll just close the PR 🙂 |
If it's hard to figure out appropriate changes to the docs, I can at least merge the tests. |
miss-islington
commented
Apr 11, 2023
Thanks @Zac-HD for the PR, and @hauntsaninja for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
(cherry picked from commit 4cd1cc8) Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
bedevere-bot
commented
Apr 11, 2023
GH-103435 is a backport of this pull request to the 3.11 branch. |
hauntsaninja
commented
Apr 11, 2023
Thank you! |
Follows #99572 (comment) to clarify a potential point of confusion. CC @iritkatriel (thank you again!)
ExceptionGroupcan wrapBaseExceptions #99553