Commit: edb9759b2d73121989564a7c3d9499b1d9efa75e
Author: Campbell Barton
Date:   Wed Apr 20 13:17:16 2022 +1000
Branches: draw-deferred-compilation-experiment
https://developer.blender.org/rBedb9759b2d73121989564a7c3d9499b1d9efa75e

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,

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to