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

PEP-654: allow subclassing of exception groups #1872

Merged
merged 4 commits into from
Mar 18, 2021

Conversation

iritkatriel
Copy link
Member

No description provided.

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)``
Copy link
Member

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()"?

Copy link
Member

@1st1 1st1 left a 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!

Copy link
Member

@gvanrossum gvanrossum left a 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 Show resolved Hide resolved
pep-0654.rst Outdated
Comment on lines 294 to 296
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
Copy link
Member

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).

Copy link
Member Author

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?

iritkatriel and others added 2 commits March 17, 2021 23:15
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants