Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Lib/test/test_coroutines.py
Original file line number Diff line number Diff line change
Expand Up @@ -2137,7 +2137,6 @@ async def func(): pass
support.gc_collect()

self.assertIn("was never awaited", str(cm.unraisable.exc_value))
self.assertEqual(repr(cm.unraisable.object), coro_repr)

def test_for_assign_raising_stop_async_iteration(self):
class BadTarget:
Expand Down Expand Up @@ -2414,7 +2413,6 @@ async def corofn():
del coro
support.gc_collect()

self.assertEqual(repr(cm.unraisable.object), coro_repr)
self.assertEqual(cm.unraisable.exc_type, ZeroDivisionError)

del warnings._warn_unawaited_coroutine
Expand Down
1 change: 0 additions & 1 deletion Lib/test/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,6 @@ def __del__(self):
del obj

gc_collect() # For PyPy or other GCs.
self.assertEqual(cm.unraisable.object, BrokenDel.__del__)
self.assertIsNotNone(cm.unraisable.exc_traceback)

def test_unhandled(self):
Expand Down
2 changes: 0 additions & 2 deletions Lib/test/test_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2779,14 +2779,12 @@ def printsolution(self, x):
... l = Leaker()
... del l
...
... cm.unraisable.object == Leaker.__del__
... cm.unraisable.exc_type == RuntimeError
... str(cm.unraisable.exc_value) == "del failed"
... cm.unraisable.exc_traceback is not None
True
True
True
True


These refleak tests should perhaps be in a testfile of their own,
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ def __del__(self):
rc, stdout, stderr = assert_python_ok("-c", code)
self.assertEqual(rc, 0)
self.assertEqual(stdout.rstrip(), b"")
self.assertIn(b"Exception ignored in:", stderr)
self.assertIn(b"Exception ignored while calling deallocator", stderr)
self.assertIn(b"C.__del__", stderr)

def test__struct_reference_cycle_cleaned_up(self):
Expand Down
12 changes: 8 additions & 4 deletions Objects/genobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ _PyGen_Finalize(PyObject *self)

PyObject *res = PyObject_CallOneArg(finalizer, self);
if (res == NULL) {
PyErr_WriteUnraisable(self);
} else {
PyErr_FormatUnraisable("Exception ignored while "
"finalizing generator %R", self);
}
else {
Py_DECREF(res);
}
/* Restore the saved exception. */
Expand All @@ -122,7 +124,8 @@ _PyGen_Finalize(PyObject *self)
PyObject *res = gen_close((PyObject*)gen, NULL);
if (res == NULL) {
if (PyErr_Occurred()) {
PyErr_WriteUnraisable(self);
PyErr_FormatUnraisable("Exception ignored while "
"closing generator %R", self);
}
}
else {
Expand Down Expand Up @@ -338,7 +341,8 @@ gen_close_iter(PyObject *yf)
else {
PyObject *meth;
if (PyObject_GetOptionalAttr(yf, &_Py_ID(close), &meth) < 0) {
PyErr_WriteUnraisable(yf);
PyErr_FormatUnraisable("Exception ignored while "
"closing generator %R", yf);
}
if (meth) {
retval = _PyObject_CallNoArgs(meth);
Expand Down
9 changes: 6 additions & 3 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -10288,10 +10288,13 @@ slot_tp_finalize(PyObject *self)
del = lookup_maybe_method(self, &_Py_ID(__del__), &unbound);
if (del != NULL) {
res = call_unbound_noarg(unbound, del, self);
if (res == NULL)
PyErr_WriteUnraisable(del);
else
if (res == NULL) {
PyErr_FormatUnraisable("Exception ignored while "
"calling deallocator %R", del);
}
else {
Py_DECREF(res);
}
Py_DECREF(del);
}

Expand Down
10 changes: 7 additions & 3 deletions Python/_warnings.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,8 @@ _PyErr_WarnUnawaitedAgenMethod(PyAsyncGenObject *agen, PyObject *method)
"coroutine method %R of %R was never awaited",
method, agen->ag_qualname) < 0)
{
PyErr_WriteUnraisable((PyObject *)agen);
PyErr_FormatUnraisable("Exception ignored while "
"finalizing async generator %R", agen);
}
PyErr_SetRaisedException(exc);
}
Expand Down Expand Up @@ -1487,14 +1488,17 @@ _PyErr_WarnUnawaitedCoroutine(PyObject *coro)
}

if (PyErr_Occurred()) {
PyErr_WriteUnraisable(coro);
PyErr_FormatUnraisable("Exception ignored while "
"finalizing coroutine %R", coro);
}

if (!warned) {
if (_PyErr_WarnFormat(coro, PyExc_RuntimeWarning, 1,
"coroutine '%S' was never awaited",
((PyCoroObject *)coro)->cr_qualname) < 0)
{
PyErr_WriteUnraisable(coro);
PyErr_FormatUnraisable("Exception ignored while "
"finalizing coroutine %R", coro);
}
}
}
Expand Down
Loading