gh-129354: Fix grammar in PyErr_FormatUnraisable() (#129475)

Replace "on verb+ing" with "while verb+ing".
This commit is contained in:
Victor Stinner 2025-01-31 09:45:35 +01:00 committed by GitHub
parent 3ebe3d7688
commit 95504f429e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 79 additions and 59 deletions

View file

@ -491,7 +491,7 @@ class CmdLineTest(unittest.TestCase):
rc, out, err = assert_python_failure('-c', code) rc, out, err = assert_python_failure('-c', code)
self.assertEqual(b'', out) self.assertEqual(b'', out)
self.assertEqual(120, rc) self.assertEqual(120, rc)
self.assertIn(b'Exception ignored on flushing sys.stdout:\n' self.assertIn(b'Exception ignored while flushing sys.stdout:\n'
b'OSError: '.replace(b'\n', os.linesep.encode()), b'OSError: '.replace(b'\n', os.linesep.encode()),
err) err)

View file

@ -324,7 +324,7 @@ class SampleCallbacksTestCase(unittest.TestCase):
self.assertIsInstance(cm.unraisable.exc_value, TypeError) self.assertIsInstance(cm.unraisable.exc_value, TypeError)
self.assertEqual(cm.unraisable.err_msg, self.assertEqual(cm.unraisable.err_msg,
f"Exception ignored on converting result " f"Exception ignored while converting result "
f"of ctypes callback function {func!r}") f"of ctypes callback function {func!r}")
self.assertIsNone(cm.unraisable.object) self.assertIsNone(cm.unraisable.object)

View file

@ -51,7 +51,7 @@ class CallbackTracbackTestCase(unittest.TestCase):
if exc_msg is not None: if exc_msg is not None:
self.assertEqual(str(cm.unraisable.exc_value), exc_msg) self.assertEqual(str(cm.unraisable.exc_value), exc_msg)
self.assertEqual(cm.unraisable.err_msg, self.assertEqual(cm.unraisable.err_msg,
f"Exception ignored on calling ctypes " f"Exception ignored while calling ctypes "
f"callback function {callback_func!r}") f"callback function {callback_func!r}")
self.assertIsNone(cm.unraisable.object) self.assertIsNone(cm.unraisable.object)

View file

@ -383,7 +383,7 @@ class WakeupSignalTests(unittest.TestCase):
except ZeroDivisionError: except ZeroDivisionError:
# An ignored exception should have been printed out on stderr # An ignored exception should have been printed out on stderr
err = err.getvalue() err = err.getvalue()
if ('Exception ignored when trying to write to the signal wakeup fd' if ('Exception ignored while trying to write to the signal wakeup fd'
not in err): not in err):
raise AssertionError(err) raise AssertionError(err)
if ('OSError: [Errno %d]' % errno.EBADF) not in err: if ('OSError: [Errno %d]' % errno.EBADF) not in err:
@ -572,7 +572,7 @@ class WakeupSocketSignalTests(unittest.TestCase):
signal.raise_signal(signum) signal.raise_signal(signum)
err = err.getvalue() err = err.getvalue()
if ('Exception ignored when trying to {action} to the signal wakeup fd' if ('Exception ignored while trying to {action} to the signal wakeup fd'
not in err): not in err):
raise AssertionError(err) raise AssertionError(err)
""".format(action=action) """.format(action=action)
@ -642,7 +642,7 @@ class WakeupSocketSignalTests(unittest.TestCase):
"buffer" % written) "buffer" % written)
# By default, we get a warning when a signal arrives # By default, we get a warning when a signal arrives
msg = ('Exception ignored when trying to {action} ' msg = ('Exception ignored while trying to {action} '
'to the signal wakeup fd') 'to the signal wakeup fd')
signal.set_wakeup_fd(write.fileno()) signal.set_wakeup_fd(write.fileno())

View file

@ -183,7 +183,8 @@ _DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw)
DictRemoverObject *self = _DictRemoverObject_CAST(myself); DictRemoverObject *self = _DictRemoverObject_CAST(myself);
if (self->key && self->dict) { if (self->key && self->dict) {
if (-1 == PyDict_DelItem(self->dict, self->key)) { if (-1 == PyDict_DelItem(self->dict, self->key)) {
PyErr_FormatUnraisable("Exception ignored on calling _ctypes.DictRemover"); PyErr_FormatUnraisable("Exception ignored while "
"calling _ctypes.DictRemover");
} }
Py_CLEAR(self->key); Py_CLEAR(self->key);
Py_CLEAR(self->dict); Py_CLEAR(self->dict);

View file

@ -225,9 +225,9 @@ static void _CallPythonObject(ctypes_state *st,
result = PyObject_Vectorcall(callable, args, nargs, NULL); result = PyObject_Vectorcall(callable, args, nargs, NULL);
if (result == NULL) { if (result == NULL) {
PyErr_FormatUnraisable( PyErr_FormatUnraisable("Exception ignored while "
"Exception ignored on calling ctypes callback function %R", "calling ctypes callback function %R",
callable); callable);
} }
#ifdef MS_WIN32 #ifdef MS_WIN32
@ -269,7 +269,7 @@ static void _CallPythonObject(ctypes_state *st,
if (keep == NULL) { if (keep == NULL) {
/* Could not convert callback result. */ /* Could not convert callback result. */
PyErr_FormatUnraisable( PyErr_FormatUnraisable(
"Exception ignored on converting result " "Exception ignored while converting result "
"of ctypes callback function %R", "of ctypes callback function %R",
callable); callable);
} }
@ -282,7 +282,7 @@ static void _CallPythonObject(ctypes_state *st,
"memory leak in callback function.", "memory leak in callback function.",
1) == -1) { 1) == -1) {
PyErr_FormatUnraisable( PyErr_FormatUnraisable(
"Exception ignored on converting result " "Exception ignored while converting result "
"of ctypes callback function %R", "of ctypes callback function %R",
callable); callable);
} }

View file

@ -226,7 +226,7 @@ clear_current_module(PyInterpreterState *interp, PyObject *expected)
goto finally; goto finally;
error: error:
PyErr_FormatUnraisable("Exception ignored when clearing _datetime module"); PyErr_FormatUnraisable("Exception ignored while clearing _datetime module");
finally: finally:
PyErr_SetRaisedException(exc); PyErr_SetRaisedException(exc);

View file

@ -933,7 +933,8 @@ profiler_dealloc(ProfilerObject *op)
if (op->flags & POF_ENABLED) { if (op->flags & POF_ENABLED) {
PyThreadState *tstate = _PyThreadState_GET(); PyThreadState *tstate = _PyThreadState_GET();
if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) { if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {
PyErr_FormatUnraisable("Exception ignored when destroying _lsprof profiler"); PyErr_FormatUnraisable("Exception ignored while "
"destroying _lsprof profiler");
} }
} }

View file

@ -428,7 +428,7 @@ allocate_too_many_code_watchers(PyObject *self, PyObject *args)
PyObject *exc = PyErr_GetRaisedException(); PyObject *exc = PyErr_GetRaisedException();
for (int i = 0; i < num_watchers; i++) { for (int i = 0; i < num_watchers; i++) {
if (PyCode_ClearWatcher(watcher_ids[i]) < 0) { if (PyCode_ClearWatcher(watcher_ids[i]) < 0) {
PyErr_FormatUnraisable("Exception ignored when " PyErr_FormatUnraisable("Exception ignored while "
"clearing code watcher"); "clearing code watcher");
break; break;
} }
@ -610,7 +610,7 @@ allocate_too_many_func_watchers(PyObject *self, PyObject *args)
PyObject *exc = PyErr_GetRaisedException(); PyObject *exc = PyErr_GetRaisedException();
for (int i = 0; i < num_watchers; i++) { for (int i = 0; i < num_watchers; i++) {
if (PyFunction_ClearWatcher(watcher_ids[i]) < 0) { if (PyFunction_ClearWatcher(watcher_ids[i]) < 0) {
PyErr_FormatUnraisable("Exception ignored when " PyErr_FormatUnraisable("Exception ignored while "
"clearing function watcher"); "clearing function watcher");
break; break;
} }
@ -757,7 +757,7 @@ allocate_too_many_context_watchers(PyObject *self, PyObject *args)
PyObject *exc = PyErr_GetRaisedException(); PyObject *exc = PyErr_GetRaisedException();
for (int i = 0; i < num_watchers; i++) { for (int i = 0; i < num_watchers; i++) {
if (PyContext_ClearWatcher(watcher_ids[i]) < 0) { if (PyContext_ClearWatcher(watcher_ids[i]) < 0) {
PyErr_FormatUnraisable("Exception ignored when " PyErr_FormatUnraisable("Exception ignored while "
"clearing context watcher"); "clearing context watcher");
break; break;
} }

View file

@ -177,7 +177,7 @@ overlapped_dealloc(OverlappedObject *self)
PyErr_SetString(PyExc_PythonFinalizationError, PyErr_SetString(PyExc_PythonFinalizationError,
"I/O operations still in flight while destroying " "I/O operations still in flight while destroying "
"Overlapped object, the process may crash"); "Overlapped object, the process may crash");
PyErr_FormatUnraisable("Exception ignored when deallocating " PyErr_FormatUnraisable("Exception ignored while deallocating "
"overlapped operation %R", self); "overlapped operation %R", self);
} }
else { else {

View file

@ -110,7 +110,7 @@ atexit_callfuncs(struct atexit_state *state)
PyObject *copy = PyList_GetSlice(state->callbacks, 0, PyList_GET_SIZE(state->callbacks)); PyObject *copy = PyList_GetSlice(state->callbacks, 0, PyList_GET_SIZE(state->callbacks));
if (copy == NULL) if (copy == NULL)
{ {
PyErr_FormatUnraisable("Exception ignored when " PyErr_FormatUnraisable("Exception ignored while "
"copying atexit callbacks"); "copying atexit callbacks");
return; return;
} }

View file

@ -955,7 +955,7 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
) { ) {
Py_DECREF(co); Py_DECREF(co);
Py_DECREF(dict); Py_DECREF(dict);
PyErr_FormatUnraisable("Exception ignored in preparing getpath"); PyErr_FormatUnraisable("Exception ignored while preparing getpath");
return PyStatus_Error("error evaluating initial values"); return PyStatus_Error("error evaluating initial values");
} }
@ -964,13 +964,13 @@ _PyConfig_InitPathConfig(PyConfig *config, int compute_path_config)
if (!r) { if (!r) {
Py_DECREF(dict); Py_DECREF(dict);
PyErr_FormatUnraisable("Exception ignored in running getpath"); PyErr_FormatUnraisable("Exception ignored while running getpath");
return PyStatus_Error("error evaluating path"); return PyStatus_Error("error evaluating path");
} }
Py_DECREF(r); Py_DECREF(r);
if (_PyConfig_FromDict(config, configDict) < 0) { if (_PyConfig_FromDict(config, configDict) < 0) {
PyErr_FormatUnraisable("Exception ignored in reading getpath results"); PyErr_FormatUnraisable("Exception ignored while reading getpath results");
Py_DECREF(dict); Py_DECREF(dict);
return PyStatus_Error("error getting getpath results"); return PyStatus_Error("error getting getpath results");
} }

View file

@ -759,7 +759,7 @@ Overlapped_dealloc(OverlappedObject *self)
PyExc_RuntimeError, PyExc_RuntimeError,
"%R still has pending operation at " "%R still has pending operation at "
"deallocation, the process may crash", self); "deallocation, the process may crash", self);
PyErr_FormatUnraisable("Exception ignored when deallocating " PyErr_FormatUnraisable("Exception ignored while deallocating "
"overlapped operation %R", self); "overlapped operation %R", self);
} }
} }

View file

@ -245,7 +245,8 @@ report_wakeup_write_error(void *data)
errno = (int) (intptr_t) data; errno = (int) (intptr_t) data;
PyObject *exc = PyErr_GetRaisedException(); PyObject *exc = PyErr_GetRaisedException();
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
PyErr_FormatUnraisable("Exception ignored when trying to write to the signal wakeup fd"); PyErr_FormatUnraisable("Exception ignored while "
"trying to write to the signal wakeup fd");
PyErr_SetRaisedException(exc); PyErr_SetRaisedException(exc);
errno = save_errno; errno = save_errno;
return 0; return 0;
@ -262,7 +263,8 @@ report_wakeup_send_error(void* data)
recognizes the error codes used by both GetLastError() and recognizes the error codes used by both GetLastError() and
WSAGetLastError */ WSAGetLastError */
PyErr_SetExcFromWindowsErr(PyExc_OSError, send_errno); PyErr_SetExcFromWindowsErr(PyExc_OSError, send_errno);
PyErr_FormatUnraisable("Exception ignored when trying to send to the signal wakeup fd"); PyErr_FormatUnraisable("Exception ignored while "
"trying to send to the signal wakeup fd");
PyErr_SetRaisedException(exc); PyErr_SetRaisedException(exc);
return 0; return 0;
} }
@ -1837,7 +1839,7 @@ _PyErr_CheckSignalsTstate(PyThreadState *tstate)
PyErr_Format(PyExc_OSError, PyErr_Format(PyExc_OSError,
"Signal %i ignored due to race condition", "Signal %i ignored due to race condition",
i); i);
PyErr_FormatUnraisable("Exception ignored when " PyErr_FormatUnraisable("Exception ignored while "
"calling signal handler"); "calling signal handler");
continue; continue;
} }

View file

@ -7351,7 +7351,7 @@ PyObject_ClearManagedDict(PyObject *obj)
if (set_or_clear_managed_dict(obj, NULL, true) < 0) { if (set_or_clear_managed_dict(obj, NULL, true) < 0) {
/* Must be out of memory */ /* Must be out of memory */
assert(PyErr_Occurred() == PyExc_MemoryError); assert(PyErr_Occurred() == PyExc_MemoryError);
PyErr_FormatUnraisable("Exception ignored when " PyErr_FormatUnraisable("Exception ignored while "
"clearing an object managed dict"); "clearing an object managed dict");
/* Clear the dict */ /* Clear the dict */
PyDictObject *dict = _PyObject_GetManagedDict(obj); PyDictObject *dict = _PyObject_GetManagedDict(obj);

View file

@ -703,7 +703,8 @@ _PyModule_ClearDict(PyObject *d)
PyErr_Clear(); PyErr_Clear();
} }
if (PyDict_SetItem(d, key, Py_None) != 0) { if (PyDict_SetItem(d, key, Py_None) != 0) {
PyErr_FormatUnraisable("Exception ignored on clearing module dict"); PyErr_FormatUnraisable("Exception ignored while "
"clearing module dict");
} }
} }
} }
@ -724,7 +725,8 @@ _PyModule_ClearDict(PyObject *d)
PyErr_Clear(); PyErr_Clear();
} }
if (PyDict_SetItem(d, key, Py_None) != 0) { if (PyDict_SetItem(d, key, Py_None) != 0) {
PyErr_FormatUnraisable("Exception ignored on clearing module dict"); PyErr_FormatUnraisable("Exception ignored while "
"clearing module dict");
} }
} }
} }

View file

@ -1042,7 +1042,8 @@ PyObject_ClearWeakRefs(PyObject *object)
PyObject *tuple = PyTuple_New(num_weakrefs * 2); PyObject *tuple = PyTuple_New(num_weakrefs * 2);
if (tuple == NULL) { if (tuple == NULL) {
_PyWeakref_ClearWeakRefsNoCallbacks(object); _PyWeakref_ClearWeakRefsNoCallbacks(object);
PyErr_FormatUnraisable("Exception ignored when clearing object weakrefs"); PyErr_FormatUnraisable("Exception ignored while "
"clearing object weakrefs");
PyErr_SetRaisedException(exc); PyErr_SetRaisedException(exc);
return; return;
} }

View file

@ -704,12 +704,12 @@ _PyCompile_ExitScope(compiler *c)
assert(c->u); assert(c->u);
/* we are deleting from a list so this really shouldn't fail */ /* we are deleting from a list so this really shouldn't fail */
if (PySequence_DelItem(c->c_stack, n) < 0) { if (PySequence_DelItem(c->c_stack, n) < 0) {
PyErr_FormatUnraisable("Exception ignored on removing " PyErr_FormatUnraisable("Exception ignored while removing "
"the last compiler stack item"); "the last compiler stack item");
} }
if (nested_seq != NULL) { if (nested_seq != NULL) {
if (_PyInstructionSequence_AddNested(c->u->u_instr_sequence, nested_seq) < 0) { if (_PyInstructionSequence_AddNested(c->u->u_instr_sequence, nested_seq) < 0) {
PyErr_FormatUnraisable("Exception ignored on appending " PyErr_FormatUnraisable("Exception ignored while appending "
"nested instruction sequence"); "nested instruction sequence");
} }
} }

View file

@ -784,7 +784,8 @@ _PyXI_excinfo_Apply(_PyXI_excinfo *info, PyObject *exctype)
PyObject *exc = PyErr_GetRaisedException(); PyObject *exc = PyErr_GetRaisedException();
if (PyObject_SetAttrString(exc, "_errdisplay", tbexc) < 0) { if (PyObject_SetAttrString(exc, "_errdisplay", tbexc) < 0) {
#ifdef Py_DEBUG #ifdef Py_DEBUG
PyErr_FormatUnraisable("Exception ignored when setting _errdisplay"); PyErr_FormatUnraisable("Exception ignored while "
"setting _errdisplay");
#endif #endif
PyErr_Clear(); PyErr_Clear();
} }

View file

@ -1633,7 +1633,7 @@ format_unraisable_v(const char *format, va_list va, PyObject *obj)
PyObject *hook_args = make_unraisable_hook_args( PyObject *hook_args = make_unraisable_hook_args(
tstate, exc_type, exc_value, exc_tb, err_msg, obj); tstate, exc_type, exc_value, exc_tb, err_msg, obj);
if (hook_args == NULL) { if (hook_args == NULL) {
err_msg_str = ("Exception ignored on building " err_msg_str = ("Exception ignored while building "
"sys.unraisablehook arguments"); "sys.unraisablehook arguments");
goto error; goto error;
} }

View file

@ -1779,7 +1779,7 @@ do_gc_callback(GCState *gcstate, const char *phase,
"collected", stats->collected, "collected", stats->collected,
"uncollectable", stats->uncollectable); "uncollectable", stats->uncollectable);
if (info == NULL) { if (info == NULL) {
PyErr_FormatUnraisable("Exception ignored on invoking gc callbacks"); PyErr_FormatUnraisable("Exception ignored while invoking gc callbacks");
return; return;
} }
} }
@ -1787,7 +1787,7 @@ do_gc_callback(GCState *gcstate, const char *phase,
PyObject *phase_obj = PyUnicode_FromString(phase); PyObject *phase_obj = PyUnicode_FromString(phase);
if (phase_obj == NULL) { if (phase_obj == NULL) {
Py_XDECREF(info); Py_XDECREF(info);
PyErr_FormatUnraisable("Exception ignored on invoking gc callbacks"); PyErr_FormatUnraisable("Exception ignored while invoking gc callbacks");
return; return;
} }

View file

@ -1427,7 +1427,8 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
"collected", collected, "collected", collected,
"uncollectable", uncollectable); "uncollectable", uncollectable);
if (info == NULL) { if (info == NULL) {
PyErr_FormatUnraisable("Exception ignored on invoking gc callbacks"); PyErr_FormatUnraisable("Exception ignored while "
"invoking gc callbacks");
return; return;
} }
} }
@ -1435,7 +1436,8 @@ invoke_gc_callback(PyThreadState *tstate, const char *phase,
PyObject *phase_obj = PyUnicode_FromString(phase); PyObject *phase_obj = PyUnicode_FromString(phase);
if (phase_obj == NULL) { if (phase_obj == NULL) {
Py_XDECREF(info); Py_XDECREF(info);
PyErr_FormatUnraisable("Exception ignored on invoking gc callbacks"); PyErr_FormatUnraisable("Exception ignored while "
"invoking gc callbacks");
return; return;
} }

View file

@ -594,7 +594,8 @@ _PyImport_ClearModulesByIndex(PyInterpreterState *interp)
if (PyList_SetSlice(MODULES_BY_INDEX(interp), if (PyList_SetSlice(MODULES_BY_INDEX(interp),
0, PyList_GET_SIZE(MODULES_BY_INDEX(interp)), 0, PyList_GET_SIZE(MODULES_BY_INDEX(interp)),
NULL)) { NULL)) {
PyErr_FormatUnraisable("Exception ignored on clearing interpreters module list"); PyErr_FormatUnraisable("Exception ignored while "
"clearing interpreters module list");
} }
} }
@ -4080,13 +4081,15 @@ _PyImport_FiniCore(PyInterpreterState *interp)
int verbose = _PyInterpreterState_GetConfig(interp)->verbose; int verbose = _PyInterpreterState_GetConfig(interp)->verbose;
if (_PySys_ClearAttrString(interp, "meta_path", verbose) < 0) { if (_PySys_ClearAttrString(interp, "meta_path", verbose) < 0) {
PyErr_FormatUnraisable("Exception ignored on clearing sys.meta_path"); PyErr_FormatUnraisable("Exception ignored while "
"clearing sys.meta_path");
} }
// XXX Pull in most of finalize_modules() in pylifecycle.c. // XXX Pull in most of finalize_modules() in pylifecycle.c.
if (_PySys_ClearAttrString(interp, "modules", verbose) < 0) { if (_PySys_ClearAttrString(interp, "modules", verbose) < 0) {
PyErr_FormatUnraisable("Exception ignored on clearing sys.modules"); PyErr_FormatUnraisable("Exception ignored while "
"clearing sys.modules");
} }
_PyImport_ClearCore(interp); _PyImport_ClearCore(interp);
@ -4161,10 +4164,12 @@ _PyImport_FiniExternal(PyInterpreterState *interp)
// XXX Uninstall importlib metapath importers here? // XXX Uninstall importlib metapath importers here?
if (_PySys_ClearAttrString(interp, "path_importer_cache", verbose) < 0) { if (_PySys_ClearAttrString(interp, "path_importer_cache", verbose) < 0) {
PyErr_FormatUnraisable("Exception ignored on clearing sys.path_importer_cache"); PyErr_FormatUnraisable("Exception ignored while "
"clearing sys.path_importer_cache");
} }
if (_PySys_ClearAttrString(interp, "path_hooks", verbose) < 0) { if (_PySys_ClearAttrString(interp, "path_hooks", verbose) < 0) {
PyErr_FormatUnraisable("Exception ignored on clearing sys.path_hooks"); PyErr_FormatUnraisable("Exception ignored while "
"clearing sys.path_hooks");
} }
} }

View file

@ -563,7 +563,8 @@ _PyJIT_Free(_PyExecutorObject *executor)
executor->jit_side_entry = NULL; executor->jit_side_entry = NULL;
executor->jit_size = 0; executor->jit_size = 0;
if (jit_free(memory, size)) { if (jit_free(memory, size)) {
PyErr_FormatUnraisable("Exception ignored when freeing JIT memory"); PyErr_FormatUnraisable("Exception ignored while "
"freeing JIT memory");
} }
} }
} }

View file

@ -1475,13 +1475,15 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
PySys_WriteStderr("# clear builtins._\n"); PySys_WriteStderr("# clear builtins._\n");
} }
if (PyDict_SetItemString(interp->builtins, "_", Py_None) < 0) { if (PyDict_SetItemString(interp->builtins, "_", Py_None) < 0) {
PyErr_FormatUnraisable("Exception ignored on setting builtin variable _"); PyErr_FormatUnraisable("Exception ignored while "
"setting builtin variable _");
} }
const char * const *p; const char * const *p;
for (p = sys_deletes; *p != NULL; p++) { for (p = sys_deletes; *p != NULL; p++) {
if (_PySys_ClearAttrString(interp, *p, verbose) < 0) { if (_PySys_ClearAttrString(interp, *p, verbose) < 0) {
PyErr_FormatUnraisable("Exception ignored on clearing sys.%s", *p); PyErr_FormatUnraisable("Exception ignored while "
"clearing sys.%s", *p);
} }
} }
for (p = sys_files; *p != NULL; p+=2) { for (p = sys_files; *p != NULL; p+=2) {
@ -1492,13 +1494,15 @@ finalize_modules_delete_special(PyThreadState *tstate, int verbose)
} }
PyObject *value; PyObject *value;
if (PyDict_GetItemStringRef(interp->sysdict, orig_name, &value) < 0) { if (PyDict_GetItemStringRef(interp->sysdict, orig_name, &value) < 0) {
PyErr_FormatUnraisable("Exception ignored on restoring sys.%s", name); PyErr_FormatUnraisable("Exception ignored while "
"restoring sys.%s", name);
} }
if (value == NULL) { if (value == NULL) {
value = Py_NewRef(Py_None); value = Py_NewRef(Py_None);
} }
if (PyDict_SetItemString(interp->sysdict, name, value) < 0) { if (PyDict_SetItemString(interp->sysdict, name, value) < 0) {
PyErr_FormatUnraisable("Exception ignored on restoring sys.%s", name); PyErr_FormatUnraisable("Exception ignored while "
"restoring sys.%s", name);
} }
Py_DECREF(value); Py_DECREF(value);
} }
@ -1510,7 +1514,7 @@ finalize_remove_modules(PyObject *modules, int verbose)
{ {
PyObject *weaklist = PyList_New(0); PyObject *weaklist = PyList_New(0);
if (weaklist == NULL) { if (weaklist == NULL) {
PyErr_FormatUnraisable("Exception ignored on removing modules"); PyErr_FormatUnraisable("Exception ignored while removing modules");
} }
#define STORE_MODULE_WEAKREF(name, mod) \ #define STORE_MODULE_WEAKREF(name, mod) \
@ -1519,13 +1523,13 @@ finalize_remove_modules(PyObject *modules, int verbose)
if (wr) { \ if (wr) { \
PyObject *tup = PyTuple_Pack(2, name, wr); \ PyObject *tup = PyTuple_Pack(2, name, wr); \
if (!tup || PyList_Append(weaklist, tup) < 0) { \ if (!tup || PyList_Append(weaklist, tup) < 0) { \
PyErr_FormatUnraisable("Exception ignored on removing modules"); \ PyErr_FormatUnraisable("Exception ignored while removing modules"); \
} \ } \
Py_XDECREF(tup); \ Py_XDECREF(tup); \
Py_DECREF(wr); \ Py_DECREF(wr); \
} \ } \
else { \ else { \
PyErr_FormatUnraisable("Exception ignored on removing modules"); \ PyErr_FormatUnraisable("Exception ignored while removing modules"); \
} \ } \
} }
@ -1536,7 +1540,7 @@ finalize_remove_modules(PyObject *modules, int verbose)
} \ } \
STORE_MODULE_WEAKREF(name, mod); \ STORE_MODULE_WEAKREF(name, mod); \
if (PyObject_SetItem(modules, name, Py_None) < 0) { \ if (PyObject_SetItem(modules, name, Py_None) < 0) { \
PyErr_FormatUnraisable("Exception ignored on removing modules"); \ PyErr_FormatUnraisable("Exception ignored while removing modules"); \
} \ } \
} }
@ -1550,14 +1554,14 @@ finalize_remove_modules(PyObject *modules, int verbose)
else { else {
PyObject *iterator = PyObject_GetIter(modules); PyObject *iterator = PyObject_GetIter(modules);
if (iterator == NULL) { if (iterator == NULL) {
PyErr_FormatUnraisable("Exception ignored on removing modules"); PyErr_FormatUnraisable("Exception ignored while removing modules");
} }
else { else {
PyObject *key; PyObject *key;
while ((key = PyIter_Next(iterator))) { while ((key = PyIter_Next(iterator))) {
PyObject *value = PyObject_GetItem(modules, key); PyObject *value = PyObject_GetItem(modules, key);
if (value == NULL) { if (value == NULL) {
PyErr_FormatUnraisable("Exception ignored on removing modules"); PyErr_FormatUnraisable("Exception ignored while removing modules");
continue; continue;
} }
CLEAR_MODULE(key, value); CLEAR_MODULE(key, value);
@ -1565,7 +1569,7 @@ finalize_remove_modules(PyObject *modules, int verbose)
Py_DECREF(key); Py_DECREF(key);
} }
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
PyErr_FormatUnraisable("Exception ignored on removing modules"); PyErr_FormatUnraisable("Exception ignored while removing modules");
} }
Py_DECREF(iterator); Py_DECREF(iterator);
} }
@ -1585,7 +1589,7 @@ finalize_clear_modules_dict(PyObject *modules)
} }
else { else {
if (PyObject_CallMethodNoArgs(modules, &_Py_ID(clear)) == NULL) { if (PyObject_CallMethodNoArgs(modules, &_Py_ID(clear)) == NULL) {
PyErr_FormatUnraisable("Exception ignored on clearing sys.modules"); PyErr_FormatUnraisable("Exception ignored while clearing sys.modules");
} }
} }
} }
@ -1597,11 +1601,11 @@ finalize_restore_builtins(PyThreadState *tstate)
PyInterpreterState *interp = tstate->interp; PyInterpreterState *interp = tstate->interp;
PyObject *dict = PyDict_Copy(interp->builtins); PyObject *dict = PyDict_Copy(interp->builtins);
if (dict == NULL) { if (dict == NULL) {
PyErr_FormatUnraisable("Exception ignored on restoring builtins"); PyErr_FormatUnraisable("Exception ignored while restoring builtins");
} }
PyDict_Clear(interp->builtins); PyDict_Clear(interp->builtins);
if (PyDict_Update(interp->builtins, interp->builtins_copy)) { if (PyDict_Update(interp->builtins, interp->builtins_copy)) {
PyErr_FormatUnraisable("Exception ignored on restoring builtins"); PyErr_FormatUnraisable("Exception ignored while restoring builtins");
} }
Py_XDECREF(dict); Py_XDECREF(dict);
} }
@ -1773,7 +1777,7 @@ flush_std_files(void)
if (fout != NULL && fout != Py_None && !file_is_closed(fout)) { if (fout != NULL && fout != Py_None && !file_is_closed(fout)) {
if (_PyFile_Flush(fout) < 0) { if (_PyFile_Flush(fout) < 0) {
PyErr_FormatUnraisable("Exception ignored on flushing sys.stdout"); PyErr_FormatUnraisable("Exception ignored while flushing sys.stdout");
status = -1; status = -1;
} }
} }