Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <campbell@blender.org>2022-04-20 06:17:16 +0300
committerCampbell Barton <campbell@blender.org>2022-04-20 06:17:16 +0300
commit972a697f822b65cc1887c305dd62e54d5b19d3e3 (patch)
treeb7e7237d3550750ce37f15410577f963a1678772
parentfeea852b10eaec8913d789e5b2609b77c281b673 (diff)
PyAPI: improve deprecation warning for bpy.ops context override
- Increase the stack level so the reported line number references script authors code (not Blender's wrapper function). - Include the operator name and poll/call usage in the warning.
-rw-r--r--source/blender/python/intern/bpy_operator.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 0cfe6dab2f5..95879b02295 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -60,12 +60,17 @@ static wmOperatorType *ot_lookup_from_py_string(PyObject *value, const char *py_
return ot;
}
-static void op_context_override_deprecated_warning(void)
+static void op_context_override_deprecated_warning(const char *action, const char *opname)
{
- if (PyErr_WarnEx(PyExc_DeprecationWarning,
- "Passing in context overrides is deprecated in favor of "
- "Context.temp_override(..)",
- 1) < 0) {
+ if (PyErr_WarnFormat(
+ PyExc_DeprecationWarning,
+ /* Use stack level 2 as this call is wrapped by `release/scripts/modules/bpy/ops.py`,
+ * An extra stack level is needed to show the warning in the authors script. */
+ 2,
+ "Passing in context overrides is deprecated in favor of "
+ "Context.temp_override(..), %s \"%s\"",
+ action,
+ opname) < 0) {
/* The function has no return value, the exception cannot
* be reported to the caller, so just log it. */
PyErr_WriteUnraisable(NULL);
@@ -126,7 +131,7 @@ static PyObject *pyop_poll(PyObject *UNUSED(self), PyObject *args)
context_dict = NULL;
}
else if (PyDict_Check(context_dict)) {
- op_context_override_deprecated_warning();
+ op_context_override_deprecated_warning("polling", opname);
}
else {
PyErr_Format(PyExc_TypeError,
@@ -234,7 +239,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
context_dict = NULL;
}
else if (PyDict_Check(context_dict)) {
- op_context_override_deprecated_warning();
+ op_context_override_deprecated_warning("calling", opname);
}
else {
PyErr_Format(PyExc_TypeError,