gh-119049: Fix incorrect display of warning which is constructed by C API (GH-119063)

The source line was not displayed if the warnings module had not yet
been imported.
This commit is contained in:
Kirill Podoprigora 2024-05-16 23:27:59 +03:00 committed by GitHub
parent 4702b7b5bd
commit 100c7ab00a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 57 additions and 4 deletions

View file

@ -569,10 +569,9 @@ call_show_warning(PyThreadState *tstate, PyObject *category,
PyObject *show_fn, *msg, *res, *warnmsg_cls = NULL;
PyInterpreterState *interp = tstate->interp;
/* If the source parameter is set, try to get the Python implementation.
The Python implementation is able to log the traceback where the source
/* The Python implementation is able to log the traceback where the source
was allocated, whereas the C implementation doesn't. */
show_fn = GET_WARNINGS_ATTR(interp, _showwarnmsg, source != NULL);
show_fn = GET_WARNINGS_ATTR(interp, _showwarnmsg, 1);
if (show_fn == NULL) {
if (PyErr_Occurred())
return -1;