GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||
GeezerVison is showing github.com — gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException by iritkatriel · Pull Request #99572 · python/cpython Conversation
|
|
Thanks @iritkatriel for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…aseException (pythonGH-99572) (cherry picked from commit c8c6113) Co-authored-by: Irit Katriel <[email protected]>
|
GH-99580 is a backport of this pull request to the 3.11 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…eption (GH-99572) (cherry picked from commit c8c6113) Co-authored-by: Irit Katriel <[email protected]>
| Like :exc:`ExceptionGroup`, any subclass of :exc:`BaseExceptionGroup` which | ||
| is also a subclass of :exc:`Exception` can only wrap instances of | ||
| :exc:`Exception`. |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As written, consistency suggests that class MyEG(BaseExceptionGroup, ValueError): should be unable to wrap anything but ValueErrors!
That may in fact be the intention, and it wouldn't break the trio.MultiError-as-BaseExceptionGroup deprecation pathway, but it's not the implementation and the tests don't distinguish these cases.
Otherwise, I think we'd want to document the behavior which is that "any subclass of ExceptionGroup can only wrap instances of Exception, like ExceptionGroup itself.", and therefore class MyEG(BaseExceptionGroup, ValueError): would be able to contain BaseExceptions 🤔
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
As written, this suggests that class MyEG(BaseExceptionGroup, ValueError): should be unable to wrap anything but ValueErrors!
Does it? In the doc the Exception becomes a hyperlink.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
But feel free to make a PR with better wording.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I expect some users to read that as "if a subclass of BaseExceptionGroup is also a subclass of X, it can only wrap instances of X"; I'll open a PR to rephrase as "if it's also a subclass of Exception, it can't wrap BaseExceptions".
But then we're still treating Exception as particularly special for subclasses, which feels a bit strange.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Zac, I'm confused why you think the sentence as written could be interpreted that way. It says Exception twice. In this context that is very clearly a reference to the specific built-in class named Exception (it even links there), not a "free variable" that must refer to the same class in both places.
Regardless, even if we clear that up, it feels like it would be expensive to inspect the class hierarchy to find other subclasses of BaseException and try to constrain the arguments to inherit from those. And that's definitely not what the PEP intended. We want the common case (where you're using one of the two built-in EG classes) to be foolproof, and other cases possible.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the confusion, that's on me 😞
I do think the behavior in this PR is good, and I'll open a PR with some additional tests and maybe docs to distinguish it from the case that I was wondering about. Thanks again to both of you for everything.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Subclasses ofExceptionGroup can wrap BaseExceptions
There was an error while loading. Please reload this page.