Skip to content

Commit

Permalink
pythongh-129354: Use PyErr_FormatUnraisable() function (python#129656)
Browse files Browse the repository at this point in the history
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().
  • Loading branch information
vstinner authored and srinivasreddy committed Feb 7, 2025
1 parent 3680b80 commit e26d7e4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ fileio_dealloc_warn(PyObject *op, PyObject *source)
PyObject *exc = PyErr_GetRaisedException();
if (PyErr_ResourceWarning(source, 1, "unclosed file %R", source)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning))
PyErr_WriteUnraisable((PyObject *) self);
if (PyErr_ExceptionMatches(PyExc_Warning)) {
PyErr_FormatUnraisable("Exception ignored "
"while finalizing file %R", self);
}
}
PyErr_SetRaisedException(exc);
}
Expand Down
3 changes: 2 additions & 1 deletion Modules/_io/iobase.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ iobase_finalize(PyObject *self)
PyErr_Clear();
res = PyObject_CallMethodNoArgs((PyObject *)self, &_Py_ID(close));
if (res == NULL) {
PyErr_WriteUnraisable(self);
PyErr_FormatUnraisable("Exception ignored "
"while finalizing file %R", self);
}
else {
Py_DECREF(res);
Expand Down
3 changes: 2 additions & 1 deletion Modules/socketmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -5359,7 +5359,8 @@ sock_finalize(PyObject *self)
if (PyErr_ResourceWarning((PyObject *)s, 1, "unclosed %R", s)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning)) {
PyErr_WriteUnraisable((PyObject *)s);
PyErr_FormatUnraisable("Exception ignored while "
"finalizing socket %R", s);
}
}

Expand Down

0 comments on commit e26d7e4

Please sign in to comment.