-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-108082: Use PyErr_FormatUnraisable() #111580
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
@@ -1032,8 +1032,8 @@ delete_garbage(PyThreadState *tstate, GCState *gcstate, | |||
Py_INCREF(op); | |||
(void) clear(op); | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -828,7 +828,7 @@ PyType_Modified(PyTypeObject *type) | |||
if (bits & 1) { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to log i variable, you should add %i
somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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().