aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Python/_warnings.c
diff options
context:
space:
mode:
authorTomas R. <tomas.roun8@gmail.com>2025-04-12 12:34:36 +0200
committerGitHub <noreply@github.com>2025-04-12 11:34:36 +0100
commit3d08c8ad20dfabd4864be139cd9c2eb5602ccdfe (patch)
treee1a0eb511b507db7c1d21be8f730504e55024e76 /Python/_warnings.c
parentd4e2cdc15bdfe84486b885eca885c44bc378fc41 (diff)
downloadcpython-3d08c8ad20dfabd4864be139cd9c2eb5602ccdfe.tar.gz
cpython-3d08c8ad20dfabd4864be139cd9c2eb5602ccdfe.zip
gh-131927: Prevent emitting optimizer warnings twice in the REPL (#131993)
Diffstat (limited to 'Python/_warnings.c')
-rw-r--r--Python/_warnings.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/Python/_warnings.c b/Python/_warnings.c
index 912468d2a59..39bf1b225cc 100644
--- a/Python/_warnings.c
+++ b/Python/_warnings.c
@@ -1479,6 +1479,28 @@ PyErr_WarnExplicitObject(PyObject *category, PyObject *message,
return 0;
}
+/* Like PyErr_WarnExplicitObject, but automatically sets up context */
+int
+_PyErr_WarnExplicitObjectWithContext(PyObject *category, PyObject *message,
+ PyObject *filename, int lineno)
+{
+ PyObject *unused_filename, *module, *registry;
+ int unused_lineno;
+ int stack_level = 1;
+
+ if (!setup_context(stack_level, NULL, &unused_filename, &unused_lineno,
+ &module, &registry)) {
+ return -1;
+ }
+
+ int rc = PyErr_WarnExplicitObject(category, message, filename, lineno,
+ module, registry);
+ Py_DECREF(unused_filename);
+ Py_DECREF(registry);
+ Py_DECREF(module);
+ return rc;
+}
+
int
PyErr_WarnExplicit(PyObject *category, const char *text,
const char *filename_str, int lineno,