From b8ce7d419ee420674ba95e70a291ba2bd4f79c16 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 20 Aug 2025 16:10:00 +1000 Subject: [PATCH] Cleanup: use PyErr_SetString when formatting isn't needed --- source/blender/python/generic/imbuf_py_api.cc | 2 +- source/blender/python/gpu/gpu_py_buffer.cc | 2 +- source/blender/python/gpu/gpu_py_element.cc | 8 ++++---- source/blender/python/gpu/gpu_py_shader.cc | 2 +- source/blender/python/intern/bpy_rna.cc | 14 +++++++------- source/blender/python/mathutils/mathutils.cc | 2 +- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/source/blender/python/generic/imbuf_py_api.cc b/source/blender/python/generic/imbuf_py_api.cc index d1be5c041d1..46c75b935f3 100644 --- a/source/blender/python/generic/imbuf_py_api.cc +++ b/source/blender/python/generic/imbuf_py_api.cc @@ -581,7 +581,7 @@ static PyObject *imbuf_load_from_memory_impl(const char *buffer, reinterpret_cast(buffer), buffer_size, flags, ""); if (ibuf == nullptr) { - PyErr_Format(PyExc_ValueError, "load_from_buffer: Unable to load image from memory"); + PyErr_SetString(PyExc_ValueError, "load_from_buffer: Unable to load image from memory"); return nullptr; } diff --git a/source/blender/python/gpu/gpu_py_buffer.cc b/source/blender/python/gpu/gpu_py_buffer.cc index e376b9c1512..81f844ee9bc 100644 --- a/source/blender/python/gpu/gpu_py_buffer.cc +++ b/source/blender/python/gpu/gpu_py_buffer.cc @@ -52,7 +52,7 @@ static bool pygpu_buffer_dimensions_tot_len_compare(const Py_ssize_t *shape_a, if (pygpu_buffer_dimensions_tot_elem(shape_a, shape_a_len) != pygpu_buffer_dimensions_tot_elem(shape_b, shape_b_len)) { - PyErr_Format(PyExc_BufferError, "array size does not match"); + PyErr_SetString(PyExc_BufferError, "array size does not match"); return false; } diff --git a/source/blender/python/gpu/gpu_py_element.cc b/source/blender/python/gpu/gpu_py_element.cc index 9ec50d9e46e..328b82894b8 100644 --- a/source/blender/python/gpu/gpu_py_element.cc +++ b/source/blender/python/gpu/gpu_py_element.cc @@ -56,9 +56,9 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject * /*type*/, PyObject *args, verts_per_prim = GPU_indexbuf_primitive_len(GPUPrimType(prim_type.value_found)); if (verts_per_prim == -1) { - PyErr_Format(PyExc_ValueError, - "The argument 'type' must be " - "'POINTS', 'LINES', 'TRIS', 'LINES_ADJ' or 'TRIS_ADJ'"); + PyErr_SetString(PyExc_ValueError, + "The argument 'type' must be " + "'POINTS', 'LINES', 'TRIS', 'LINES_ADJ' or 'TRIS_ADJ'"); return nullptr; } @@ -79,7 +79,7 @@ static PyObject *pygpu_IndexBuf__tp_new(PyTypeObject * /*type*/, PyObject *args, if (pybuffer.itemsize != 4 || PyC_StructFmt_type_is_float_any(PyC_StructFmt_type_from_str(pybuffer.format))) { - PyErr_Format(PyExc_ValueError, "Each index must be an 4-bytes integer value"); + PyErr_SetString(PyExc_ValueError, "Each index must be an 4-bytes integer value"); PyBuffer_Release(&pybuffer); return nullptr; } diff --git a/source/blender/python/gpu/gpu_py_shader.cc b/source/blender/python/gpu/gpu_py_shader.cc index 091371005c3..57818aeec9b 100644 --- a/source/blender/python/gpu/gpu_py_shader.cc +++ b/source/blender/python/gpu/gpu_py_shader.cc @@ -965,7 +965,7 @@ static PyObject *pygpu_shader_from_builtin(PyObject * /*self*/, PyObject *args, eGPUShaderConfig(pygpu_config.value_found)); if (shader == nullptr) { - PyErr_Format(PyExc_ValueError, "Builtin shader doesn't exist in the requested config"); + PyErr_SetString(PyExc_ValueError, "Builtin shader doesn't exist in the requested config"); return nullptr; } diff --git a/source/blender/python/intern/bpy_rna.cc b/source/blender/python/intern/bpy_rna.cc index eee4a1682a1..11d037c57fd 100644 --- a/source/blender/python/intern/bpy_rna.cc +++ b/source/blender/python/intern/bpy_rna.cc @@ -2885,9 +2885,9 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val if (value == Py_None) { if (RNA_property_flag(self->prop) & PROP_NEVER_NULL) { - PyErr_Format(PyExc_TypeError, - "bpy_prop_collection[key] = value: invalid, " - "this collection doesn't support None assignment"); + PyErr_SetString(PyExc_TypeError, + "bpy_prop_collection[key] = value: invalid, " + "this collection doesn't support None assignment"); return -1; } @@ -2914,9 +2914,9 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val return 0; /* OK, this is the correct type! */ } - PyErr_Format(PyExc_TypeError, - "bpy_prop_collection[key] = value: internal error, " - "failed to get the collection type"); + PyErr_SetString(PyExc_TypeError, + "bpy_prop_collection[key] = value: internal error, " + "failed to get the collection type"); return -1; } @@ -5974,7 +5974,7 @@ static PyObject *pyprop_array_foreach_getset(BPy_PropertyArrayRNA *self, PyObject *seq; if (!ELEM(prop_type, PROP_INT, PROP_FLOAT)) { - PyErr_Format(PyExc_TypeError, "foreach_get/set available only for int and float"); + PyErr_SetString(PyExc_TypeError, "foreach_get/set available only for int and float"); return nullptr; } diff --git a/source/blender/python/mathutils/mathutils.cc b/source/blender/python/mathutils/mathutils.cc index 0a478160a61..d70cb99d798 100644 --- a/source/blender/python/mathutils/mathutils.cc +++ b/source/blender/python/mathutils/mathutils.cc @@ -652,7 +652,7 @@ int _BaseMathObject_RaiseBufferViewExc(BaseMathObject *self, Py_buffer *view, in return -1; } if (UNLIKELY(self->flag & BASE_MATH_FLAG_IS_FROZEN)) { - PyErr_Format(PyExc_BufferError, "Data is frozen, cannot get a writable buffer"); + PyErr_SetString(PyExc_BufferError, "Data is frozen, cannot get a writable buffer"); return -1; } }