Skip to content

GH-146096: Fix base exception group repr#146141

Open
sergey-miryanov wants to merge 3 commits intopython:mainfrom
sergey-miryanov:bug/146096-fix-base-exception-group-repr
Open

GH-146096: Fix base exception group repr#146141
sergey-miryanov wants to merge 3 commits intopython:mainfrom
sergey-miryanov:bug/146096-fix-base-exception-group-repr

Conversation

@sergey-miryanov
Copy link
Contributor

@sergey-miryanov sergey-miryanov commented Mar 18, 2026

Fix segfault when calling repr for BaseExceptionGroup.

cc @dr-carlos

@dr-carlos
Copy link
Contributor

dr-carlos commented Mar 18, 2026

Thanks for the fix @sergey-miryanov! All looks good to me.
My apologies for not considering that args was mutable in the first implementation!

It's a pity that we don't preserve the list-like repr (ExceptionGroup('msg', [ValueError()])) in this case. But mutating the args to something without an exceptions list in it seems like a weird enough use case that we can just do this?
If this is something that people actually do (why?), we could just set the self->excs_str in all cases, but that can be quite inefficient and I'd really prefer not to.

* with self.exceptions. Instead, use self.exceptions for accuracy,
* making it look like self.args[1] for backwards compatibility. */
if (PyList_Check(PyTuple_GET_ITEM(self->args, 1))) {
if (PyTuple_GET_SIZE(self->args) == 2 && PyList_Check(PyTuple_GET_ITEM(self->args, 1))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to check that it's a Tuple first?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

3 participants