diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2022-02-22 18:28:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-22 18:28:58 (GMT) |
commit | 38b5acf8673ce42a401263a2528202e44d6ae60a (patch) | |
tree | 268428aef9ba81cf2d28a6b4e5b62cc2fe99cf40 /Objects | |
parent | bba8008f99d615a02984422a3825082bb5621f5a (diff) | |
download | cpython-38b5acf8673ce42a401263a2528202e44d6ae60a.zip cpython-38b5acf8673ce42a401263a2528202e44d6ae60a.tar.gz cpython-38b5acf8673ce42a401263a2528202e44d6ae60a.tar.bz2 |
bpo-46729: add number of sub-exceptions in str() of BaseExceptionGroup (GH-31294)
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/exceptions.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Objects/exceptions.c b/Objects/exceptions.c index 9b1c9f1..977dce5 100644 --- a/Objects/exceptions.c +++ b/Objects/exceptions.c @@ -836,7 +836,12 @@ BaseExceptionGroup_str(PyBaseExceptionGroupObject *self) { assert(self->msg); assert(PyUnicode_Check(self->msg)); - return Py_NewRef(self->msg); + + assert(PyTuple_CheckExact(self->excs)); + Py_ssize_t num_excs = PyTuple_Size(self->excs); + return PyUnicode_FromFormat( + "%S (%zd sub-exception%s)", + self->msg, num_excs, num_excs > 1 ? "s" : ""); } static PyObject * |