PyAPI: correct unregister/register mix up in exception message
Use a shared prefix for messages to avoid copy-paste errors. Also include class name in the exception if the class can't be unregistered.
This commit is contained in:
@@ -9786,24 +9786,24 @@ static PyObject *pyrna_register_class(PyObject * /*self*/, PyObject *py_class)
|
||||
|
||||
if (!PyType_Check(py_class)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"register_class(...): "
|
||||
"expected a class argument, not '%.200s'",
|
||||
"%s expected a class argument, not '%.200s'",
|
||||
error_prefix,
|
||||
Py_TYPE(py_class)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"register_class(...): "
|
||||
"already registered as a subclass '%.200s'",
|
||||
"%s already registered as a subclass '%.200s'",
|
||||
error_prefix,
|
||||
((PyTypeObject *)py_class)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!pyrna_write_check()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"register_class(...): "
|
||||
"can't run in readonly state '%.200s'",
|
||||
"%s can't run in readonly state '%.200s'",
|
||||
error_prefix,
|
||||
((PyTypeObject *)py_class)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -9818,8 +9818,8 @@ static PyObject *pyrna_register_class(PyObject * /*self*/, PyObject *py_class)
|
||||
#if 0
|
||||
if (RNA_struct_py_type_get(srna)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"register_class(...): %.200s's parent class %.200s is already registered, this "
|
||||
"is not allowed",
|
||||
"%s %.200s's parent class %.200s is already registered, this is not allowed",
|
||||
error_prefix,
|
||||
((PyTypeObject *)py_class)->tp_name,
|
||||
RNA_struct_identifier(srna));
|
||||
return nullptr;
|
||||
@@ -9831,8 +9831,9 @@ static PyObject *pyrna_register_class(PyObject * /*self*/, PyObject *py_class)
|
||||
|
||||
if (!reg) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"register_class(...): expected a subclass of a registerable "
|
||||
"%s expected a subclass of a registerable "
|
||||
"RNA type (%.200s does not support registration)",
|
||||
error_prefix,
|
||||
RNA_struct_identifier(srna));
|
||||
return nullptr;
|
||||
}
|
||||
@@ -9964,40 +9965,40 @@ static PyObject *pyrna_unregister_class(PyObject * /*self*/, PyObject *py_class)
|
||||
StructUnregisterFunc unreg;
|
||||
StructRNA *srna;
|
||||
PyObject *py_cls_meth;
|
||||
const char *error_prefix = "unregister_class(...):";
|
||||
|
||||
if (!PyType_Check(py_class)) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"register_class(...): "
|
||||
"expected a class argument, not '%.200s'",
|
||||
"%s expected a class argument, not '%.200s'",
|
||||
error_prefix,
|
||||
Py_TYPE(py_class)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (PyDict_GetItem(((PyTypeObject *)py_class)->tp_dict, bpy_intern_str_bl_rna) == nullptr) {
|
||||
PWM_cursor_wait(false);
|
||||
PyErr_SetString(PyExc_ValueError, "unregister_class(): not a registered as a subclass");
|
||||
PyErr_Format(PyExc_ValueError, "%s not a registered as a subclass", error_prefix);
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!pyrna_write_check()) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"unregister_class(...): "
|
||||
"can't run in readonly state '%.200s'",
|
||||
"%s can't run in readonly state '%.200s'",
|
||||
error_prefix,
|
||||
((PyTypeObject *)py_class)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
srna = pyrna_struct_as_srna(py_class, false, "unregister_class(...):");
|
||||
srna = pyrna_struct_as_srna(py_class, false, error_prefix);
|
||||
if (srna == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if ((srna->flag & STRUCT_RUNTIME) == 0) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"unregister_class(...): "
|
||||
"can't unregister a built-in class '%.200s'",
|
||||
"%s can't unregister a built-in class '%.200s'",
|
||||
error_prefix,
|
||||
((PyTypeObject *)py_class)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
@@ -10006,10 +10007,11 @@ static PyObject *pyrna_unregister_class(PyObject * /*self*/, PyObject *py_class)
|
||||
unreg = RNA_struct_unregister(srna);
|
||||
|
||||
if (!unreg) {
|
||||
PyErr_SetString(
|
||||
PyExc_ValueError,
|
||||
"unregister_class(...): "
|
||||
"expected a Type subclassed from a registerable RNA type (no unregister supported)");
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s expected type '%.200s' subclassed from a registerable RNA type "
|
||||
"(unregister not supported)",
|
||||
error_prefix,
|
||||
((PyTypeObject *)py_class)->tp_name);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -10053,8 +10055,8 @@ static PyObject *pyrna_unregister_class(PyObject * /*self*/, PyObject *py_class)
|
||||
|
||||
if (prop_identifier) {
|
||||
PyErr_Format(PyExc_RuntimeError,
|
||||
"unregister_class(...): can't unregister %s because %s.%s pointer property is "
|
||||
"using this",
|
||||
"%s can't unregister %s because %s.%s pointer property is using this",
|
||||
error_prefix,
|
||||
RNA_struct_identifier(srna),
|
||||
RNA_struct_identifier(srna_iter),
|
||||
prop_identifier);
|
||||
|
||||
Reference in New Issue
Block a user