gh-77757: replace exception wrapping by PEP-678 notes in typeobject's __set_name__ (#103402)

This commit is contained in:
Irit Katriel 2023-04-11 11:53:06 +01:00 committed by GitHub
parent e071f00aae
commit 55c99d97e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 55 additions and 41 deletions

View file

@ -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)
{