gh-108082: Use PyErr_FormatUnraisable()#111580
Conversation
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable().
Modules/gcmodule.c
Outdated
| if (_PyErr_Occurred(tstate)) { | ||
| _PyErr_WriteUnraisableMsg("in tp_clear of", | ||
| (PyObject*)Py_TYPE(op)); | ||
| PyErr_FormatUnraisable("Exception ignored in tp_clear of %.200s", |
There was a problem hiding this comment.
IMO %.200s is a bug here. We should no longer truncate type names if they are too long. Many years ago, Python had an internal buffer of a fixed size and so the overall string must not be too long. But this has been fixed.
Please don't truncate type names.
Objects/moduleobject.c
Outdated
| PyErr_FormatUnraisable("Exception ignored in m_clear of module%s%V\n", | ||
| m->md_name ? " " : "", | ||
| m->md_name, ""); |
There was a problem hiding this comment.
| PyErr_FormatUnraisable("Exception ignored in m_clear of module%s%V\n", | |
| m->md_name ? " " : "", | |
| m->md_name, ""); | |
| PyErr_FormatUnraisable("Exception ignored in m_clear of module%s%V", | |
| m->md_name ? " " : "", | |
| m->md_name); |
Objects/typeobject.c
Outdated
| PyType_WatchCallback cb = interp->type_watchers[i]; | ||
| if (cb && (cb(type) < 0)) { | ||
| PyErr_WriteUnraisable((PyObject *)type); | ||
| PyErr_FormatUnraisable("Exception ignored in watcher callback for %R", i, type); |
There was a problem hiding this comment.
If you want to log i variable, you should add %i somewhere.
vstinner
left a comment
There was a problem hiding this comment.
LGTM. I just left two minor suggestions.
| PyErr_WriteUnraisable(NULL); | ||
| PyErr_FormatUnraisable("Exception ignored in m_clear of module%s%V", | ||
| m->md_name ? " " : "", | ||
| m->md_name, ""); |
There was a problem hiding this comment.
The last "" is not used, it can be removed.
Co-authored-by: Victor Stinner <[email protected]>
|
|
I wanted to do this change for many years. It's awful to get a warning without any context :-( Thanks for this nice enhancement! I like PyErr_FormatUnraisable() API! |
|
We both wanted it. But other tasks had higher priorities. |
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <[email protected]>
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <[email protected]>
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable(). Co-authored-by: Victor Stinner <[email protected]>
Replace most of calls of _PyErr_WriteUnraisableMsg() and some calls of PyErr_WriteUnraisable(NULL) with PyErr_FormatUnraisable().