summaryrefslogtreecommitdiffstats
path: root/Python/errors.c
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-04-11 10:53:06 (GMT)
committerGitHub <noreply@github.com>2023-04-11 10:53:06 (GMT)
commit55c99d97e14618dfce41472dd4446f763b0da13f (patch)
tree457a036aa57a59204105937c6cba43f3ce6ba288 /Python/errors.c
parente071f00aaefae9eccf787d5c50396c26c8616483 (diff)
downloadcpython-55c99d97e14618dfce41472dd4446f763b0da13f.zip
cpython-55c99d97e14618dfce41472dd4446f763b0da13f.tar.gz
cpython-55c99d97e14618dfce41472dd4446f763b0da13f.tar.bz2
gh-77757: replace exception wrapping by PEP-678 notes in typeobject's __set_name__ (#103402)
Diffstat (limited to 'Python/errors.c')
-rw-r--r--Python/errors.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/Python/errors.c b/Python/errors.c
index ab14770..0ff6a0d 100644
--- a/Python/errors.c
+++ b/Python/errors.c
@@ -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)
{