From 28878140cdbf27fb610cbfe3c16ed45505736b0c Mon Sep 17 00:00:00 2001 From: Phil Thompson Date: Mon, 1 Jun 2026 13:24:54 +0100 Subject: [PATCH 1/2] Document that `PyErr_SetRaisedException()` accepts `NULL` Documented that `PyErr_SetRaisedException()` accepts `NULL` as the value of the exception being set. --- Doc/c-api/exceptions.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index fd9ea6272df7d8..a6b2d90314e3af 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -503,7 +503,8 @@ Querying the error indicator .. warning:: - This call steals a reference to *exc*, which must be a valid exception. + *exc* must be a valid exception (in which case a reference is stolen) or + ``NULL``. .. versionadded:: 3.12 From 4d0717287f0e5de8fa063f7b5e5565d2912cc9d0 Mon Sep 17 00:00:00 2001 From: Phil Thompson Date: Wed, 3 Jun 2026 11:09:03 +0100 Subject: [PATCH 2/2] Document that `PyErr_SetRaisedException()` accepts `NULL` Removed the warning and expanded the main part of the explanation. --- Doc/c-api/exceptions.rst | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/Doc/c-api/exceptions.rst b/Doc/c-api/exceptions.rst index 2b199f33cbf311..40b75ad34efc3b 100644 --- a/Doc/c-api/exceptions.rst +++ b/Doc/c-api/exceptions.rst @@ -498,13 +498,9 @@ Querying the error indicator .. c:function:: void PyErr_SetRaisedException(PyObject *exc) - Set *exc* as the exception currently being raised, - clearing the existing exception if one is set. - - .. warning:: - - *exc* must be a valid exception (in which case a reference is stolen) or - ``NULL``. + A stolen reference to *exc* is set as the exception currently being raised, + clearing the existing exception if one is set. *exc* may be ``NULL`` in + which case any current exception is cleared. .. versionadded:: 3.12