mirror of
https://github.com/python/cpython.git
synced 2026-04-15 00:00:57 +00:00
GH-146096: Fix segfault in BaseExceptionGroup repr (#146141)
This commit is contained in:
parent
004ce8d97b
commit
ced64605be
3 changed files with 16 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
Fixed segmentation fault when called repr for BaseExceptionGroup with empty
|
||||
or 1-size tuple args.
|
||||
|
|
@ -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))) {
|
||||
PyObject *exceptions_list = PySequence_List(self->excs);
|
||||
if (!exceptions_list) {
|
||||
return NULL;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue