[Bf-blender-cvs] [972a697f822] master: PyAPI: improve deprecation warning for bpy.ops context override

Campbell Barton noreply at git.blender.org
Wed Apr 20 05:20:14 CEST 2022


Commit: 972a697f822b65cc1887c305dd62e54d5b19d3e3
Author: Campbell Barton
Date:   Wed Apr 20 13:17:16 2022 +1000
Branches: master
https://developer.blender.org/rB972a697f822b65cc1887c305dd62e54d5b19d3e3

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.

===================================================================

M	source/blender/python/intern/bpy_operator.c

===================================================================

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,



More information about the Bf-blender-cvs mailing list