mirror of
https://github.com/python/cpython.git
synced 2025-07-08 03:45:36 +00:00
gh-77757: replace exception wrapping by PEP-678 notes in typeobject's __set_name__ (#103402)
This commit is contained in:
parent
e071f00aae
commit
55c99d97e1
8 changed files with 55 additions and 41 deletions
|
@ -1200,6 +1200,33 @@ PyErr_Format(PyObject *exception, const char *format, ...)
|
|||
}
|
||||
|
||||
|
||||
/* Adds a note to the current exception (if any) */
|
||||
void
|
||||
_PyErr_FormatNote(const char *format, ...)
|
||||
{
|
||||
PyObject *exc = PyErr_GetRaisedException();
|
||||
if (exc == NULL) {
|
||||
return;
|
||||
}
|
||||
va_list vargs;
|
||||
va_start(vargs, format);
|
||||
PyObject *note = PyUnicode_FromFormatV(format, vargs);
|
||||
va_end(vargs);
|
||||
if (note == NULL) {
|
||||
goto error;
|
||||
}
|
||||
int res = _PyException_AddNote(exc, note);
|
||||
Py_DECREF(note);
|
||||
if (res < 0) {
|
||||
goto error;
|
||||
}
|
||||
PyErr_SetRaisedException(exc);
|
||||
return;
|
||||
error:
|
||||
_PyErr_ChainExceptions1(exc);
|
||||
}
|
||||
|
||||
|
||||
PyObject *
|
||||
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue