https://github.com/python/cpython/commit/14489c1bb44dc2f4179278463fedd9a940b63f41
commit: 14489c1bb44dc2f4179278463fedd9a940b63f41
branch: main
author: Victor Stinner <[email protected]>
committer: vstinner <[email protected]>
date: 2025-02-04T16:21:10+01:00
summary:

gh-129354: Use PyErr_FormatUnraisable() function (#129656)

Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().

files:
M Modules/_io/fileio.c
M Modules/_io/iobase.c
M Modules/socketmodule.c

diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index cf0f1d671b507a..f27f2ed4843271 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -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);
     }
diff --git a/Modules/_io/iobase.c b/Modules/_io/iobase.c
index 419e5516b5c11e..f87043df126895 100644
--- a/Modules/_io/iobase.c
+++ b/Modules/_io/iobase.c
@@ -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);
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index b178eb42ac8e6a..4b6d2dd1c5fc7b 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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);
             }
         }
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to