diff --git a/src/_pyawaitable/backport.c b/src/_pyawaitable/backport.c index c1b2a89..f3a1545 100644 --- a/src/_pyawaitable/backport.c +++ b/src/_pyawaitable/backport.c @@ -41,7 +41,9 @@ PyErr_GetRaisedException(void) void PyErr_SetRaisedException(PyObject *err) { - PyErr_Restore((PyObject *) Py_TYPE(err), err, NULL); + // NOTE: We need to incref the type object here, even though + // this function steals a reference to err. + PyErr_Restore(Py_NewRef((PyObject *) Py_TYPE(err)), err, NULL); } #endif diff --git a/tests/test_awaitable.py b/tests/test_awaitable.py index 5f83518..ebbcac8 100644 --- a/tests/test_awaitable.py +++ b/tests/test_awaitable.py @@ -150,8 +150,6 @@ def cb_err(awaitable_inner: pyawaitable.PyAwaitable, err: Exception) -> int: assert called is True -""" - @limit_leaks(LEAK_LIMIT) @pytest.mark.asyncio async def test_await_cb_err_norestore(): @@ -444,4 +442,3 @@ async def coro(): ... add_await(awaitable, coro(), cb, awaitcallback_err(0)) await awaitable -"""