Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions 12 Lib/test/test_exception_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ class MyEG(ExceptionGroup):
"ExceptionGroup('test', deque([ValueError(1), TypeError(2)]))"
)

def test_repr_small_size_args(self):
eg = ExceptionGroup("msg", [ValueError()])
eg.args = ()
# repr of the ExceptionGroup with empty args should not crash
self.assertEqual(repr(eg), "ExceptionGroup('msg', (ValueError(),))")

eg.args = (1,)
# repr of the ExceptionGroup with 1-size args should not crash
self.assertEqual(repr(eg), "ExceptionGroup('msg', (ValueError(),))")



def test_repr_raises(self):
class MySeq(collections.abc.Sequence):
def __init__(self, raises):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed segmentation fault when called repr for BaseExceptionGroup with empty
or 1-size tuple args.
3 changes: 2 additions & 1 deletion 3 Objects/exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,8 @@ BaseExceptionGroup_repr(PyObject *op)
* value of self.args[1]; but this can be mutable and go out-of-sync
* 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))) {
assert(PyTuple_Check(self->args));
if (PyTuple_GET_SIZE(self->args) == 2 && PyList_Check(PyTuple_GET_ITEM(self->args, 1))) {

Copy link
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could add an assert just so it reads like it makes sense.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

PyObject *exceptions_list = PySequence_List(self->excs);
if (!exceptions_list) {
return NULL;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.