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

@ -3303,6 +3303,15 @@ failed:
return NULL;
}
static PyObject *
function_set_warning(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
{
if (PyErr_WarnEx(PyExc_RuntimeWarning, "Testing PyErr_WarnEx", 2)) {
return NULL;
}
Py_RETURN_NONE;
}
static PyMethodDef TestMethods[] = {
{"set_errno", set_errno, METH_VARARGS},
{"test_config", test_config, METH_NOARGS},
@ -3444,6 +3453,7 @@ static PyMethodDef TestMethods[] = {
{"function_set_closure", function_set_closure, METH_VARARGS, NULL},
{"check_pyimport_addmodule", check_pyimport_addmodule, METH_VARARGS},
{"test_weakref_capi", test_weakref_capi, METH_NOARGS},
{"function_set_warning", function_set_warning, METH_NOARGS},
{NULL, NULL} /* sentinel */
};