mirror of
https://github.com/python/cpython.git
synced 2025-07-19 01:05:26 +00:00
[3.13] gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function (GH-128079) (#128139)
gh-128049: Fix type confusion bug with the return value of a custom ExceptionGroup split function (GH-128079)
(cherry picked from commit 3879ca0100
)
Co-authored-by: Nico-Posada <102486290+Nico-Posada@users.noreply.github.com>
This commit is contained in:
parent
43586a4804
commit
09d15aa9a8
3 changed files with 67 additions and 2 deletions
|
@ -2029,8 +2029,25 @@ _PyEval_ExceptionGroupMatch(PyObject* exc_value, PyObject *match_type,
|
|||
if (pair == NULL) {
|
||||
return -1;
|
||||
}
|
||||
assert(PyTuple_CheckExact(pair));
|
||||
assert(PyTuple_GET_SIZE(pair) == 2);
|
||||
|
||||
if (!PyTuple_CheckExact(pair)) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s.split must return a tuple, not %.200s",
|
||||
Py_TYPE(exc_value)->tp_name, Py_TYPE(pair)->tp_name);
|
||||
Py_DECREF(pair);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// allow tuples of length > 2 for backwards compatibility
|
||||
if (PyTuple_GET_SIZE(pair) < 2) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s.split must return a 2-tuple, "
|
||||
"got tuple of size %zd",
|
||||
Py_TYPE(exc_value)->tp_name, PyTuple_GET_SIZE(pair));
|
||||
Py_DECREF(pair);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*match = Py_NewRef(PyTuple_GET_ITEM(pair, 0));
|
||||
*rest = Py_NewRef(PyTuple_GET_ITEM(pair, 1));
|
||||
Py_DECREF(pair);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue