-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException #99572
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Core and Builtins/2022-11-18-11-24-25.gh-issue-99553.F64h-n.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix bug where an :exc:`ExceptionGroup` subclass can wrap a | ||
:exc:`BaseException`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for 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 butValueError
s!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 ofException
, likeExceptionGroup
itself.", and thereforeclass MyEG(BaseExceptionGroup, ValueError):
would be able to containBaseException
s 🤔There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it? In the doc the Exception becomes a hyperlink.
There was a problem hiding this comment.
Choose a reason for 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.
There was a problem hiding this comment.
Choose a reason for 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.There was a problem hiding this comment.
Choose a reason for 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 namedException
(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.There was a problem hiding this comment.
Choose a reason for 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.