diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-05-17 15:16:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-17 15:16:58 (GMT) |
commit | ced71d39cfc2ab6e227824fe891101dcb473c2e3 (patch) | |
tree | 80b0bb5f4fe7fbfe0389c5a37097b5213a37632b /Modules | |
parent | ada4ad0e247279f54e7e2f90397075fb65bb9b5d (diff) | |
download | cpython-ced71d39cfc2ab6e227824fe891101dcb473c2e3.zip cpython-ced71d39cfc2ab6e227824fe891101dcb473c2e3.tar.gz cpython-ced71d39cfc2ab6e227824fe891101dcb473c2e3.tar.bz2 |
[3.13] gh-119049: Fix incorrect display of warning which is constructed by C API (GH-119063) (GH-119106)
The source line was not displayed if the warnings module had not yet
been imported.
(cherry picked from commit 100c7ab00ab66a8c0d54582f35e38d8eb691743c)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_testcapimodule.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index ff31724..f99ebf0 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -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 */ }; |