-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PEP-654: allow subclassing of exception groups #1872
Conversation
pep-0654.rst
Outdated
It is possible to subclass exception groups, but when doing that it is | ||
usually necessary to specify how ``subgroup()`` and ``split()`` should | ||
create new instances for the matching or non-matching part of the partition. | ||
``BaseExceptionGroup`` exposes an instance method ``derive_new(self, excs)`` |
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.
Maybe we call it "derive()"?
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.
Overall LGTM. I'm super happy that you found a way to make ExceptionGroups subclassable!
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.
Sorry for the slow review -- I'm swamped.
pep-0654.rst
Outdated
Note that we override ``__new__`` rather than ``__init__``; this is because | ||
``BaseExceptionGroup`` has a ``__new__`` method whose signature doesn't match | ||
that of our new type. Note also that our ``derive`` function does not |
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.
Well, it must override "the constructor" (i.e. either new or init) because it has a different signature; it must override new rather than init because ExceptionGroup has immutable fields (message and exceptions).
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.
Is it because of immutability, or because of the selection between ExceptionGroup and BaseExceptionGroup depending on their types? Or both?
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
No description provided.