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.
This commit is contained in:
Campbell Barton 2022-04-20 13:17:16 +10:00
parent feea852b10
commit 972a697f82
1 changed files with 12 additions and 7 deletions

View File

@ -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,