mirror of
https://github.com/python/cpython.git
synced 2025-08-30 05:35:08 +00:00
[3.12] gh-128799: Add frame of except* to traceback when wrapping a naked exception (GH-128971) (#129328)
This commit is contained in:
parent
ddb314f598
commit
d2f551db12
5 changed files with 40 additions and 3 deletions
|
@ -20,6 +20,7 @@
|
|||
#include "pycore_range.h" // _PyRangeIterObject
|
||||
#include "pycore_sliceobject.h" // _PyBuildSlice_ConsumeRefs
|
||||
#include "pycore_sysmodule.h" // _PySys_Audit()
|
||||
#include "pycore_traceback.h" // _PyTraceBack_FromFrame
|
||||
#include "pycore_tuple.h" // _PyTuple_ITEMS()
|
||||
#include "pycore_typeobject.h" // _PySuper_Lookup()
|
||||
#include "pycore_emscripten_signal.h" // _Py_CHECK_EMSCRIPTEN_SIGNALS
|
||||
|
@ -544,6 +545,7 @@ fail:
|
|||
|
||||
static int do_raise(PyThreadState *tstate, PyObject *exc, PyObject *cause);
|
||||
static int exception_group_match(
|
||||
_PyInterpreterFrame *frame,
|
||||
PyObject* exc_value, PyObject *match_type,
|
||||
PyObject **match, PyObject **rest);
|
||||
|
||||
|
@ -1856,7 +1858,7 @@ raise_error:
|
|||
*/
|
||||
|
||||
static int
|
||||
exception_group_match(PyObject* exc_value, PyObject *match_type,
|
||||
exception_group_match(_PyInterpreterFrame *frame, PyObject* exc_value, PyObject *match_type,
|
||||
PyObject **match, PyObject **rest)
|
||||
{
|
||||
if (Py_IsNone(exc_value)) {
|
||||
|
@ -1883,6 +1885,15 @@ exception_group_match(PyObject* exc_value, PyObject *match_type,
|
|||
if (wrapped == NULL) {
|
||||
return -1;
|
||||
}
|
||||
PyFrameObject *f = _PyFrame_GetFrameObject(frame);
|
||||
if (f != NULL) {
|
||||
PyObject *tb = _PyTraceBack_FromFrame(NULL, f);
|
||||
if (tb == NULL) {
|
||||
return -1;
|
||||
}
|
||||
PyException_SetTraceback(wrapped, tb);
|
||||
Py_DECREF(tb);
|
||||
}
|
||||
*match = wrapped;
|
||||
}
|
||||
*rest = Py_NewRef(Py_None);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue