From 3d48d99647b59a6f0461baa4456660917f1bbda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 7 Aug 2020 12:41:06 +0200 Subject: Cleanup: Python, Clang-Tidy else-after-return fixes This addresses warnings from Clang-Tidy's `readability-else-after-return` rule in the `source/blender/python` module. No functional changes. --- source/blender/python/intern/bpy_rna.c | 839 ++++++++++++++++----------------- 1 file changed, 398 insertions(+), 441 deletions(-) (limited to 'source/blender/python/intern/bpy_rna.c') diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 893832b61b6..955a24bc880 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -987,24 +987,23 @@ static PyObject *pyrna_prop_str(BPy_PropertyRNA *self) PyErr_SetString(PyExc_RuntimeError, "could not use property type, internal error"); return NULL; } - else { - /* This should never fail. */ - int len = -1; - char *c = type_fmt; - while ((*c++ = tolower(*type_id++))) { - } + /* This should never fail. */ + int len = -1; + char *c = type_fmt; - if (type == PROP_COLLECTION) { - len = pyrna_prop_collection_length(self); - } - else if (RNA_property_array_check(self->prop)) { - len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self); - } + while ((*c++ = tolower(*type_id++))) { + } - if (len != -1) { - sprintf(--c, "[%d]", len); - } + if (type == PROP_COLLECTION) { + len = pyrna_prop_collection_length(self); + } + else if (RNA_property_array_check(self->prop)) { + len = pyrna_prop_array_length((BPy_PropertyArrayRNA *)self); + } + + if (len != -1) { + sprintf(--c, "[%d]", len); } /* If a pointer, try to print name of pointer target too. */ @@ -1246,17 +1245,16 @@ static int pyrna_string_to_enum( Py_TYPE(item)->tp_name); return -1; } - else { - if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, r_value)) { - const char *enum_str = pyrna_enum_as_string(ptr, prop); - PyErr_Format(PyExc_TypeError, - "%.200s enum \"%.200s\" not found in (%s)", - error_prefix, - param, - enum_str); - MEM_freeN((void *)enum_str); - return -1; - } + + if (!RNA_property_enum_value(BPy_GetContext(), ptr, prop, param, r_value)) { + const char *enum_str = pyrna_enum_as_string(ptr, prop); + PyErr_Format(PyExc_TypeError, + "%.200s enum \"%.200s\" not found in (%s)", + error_prefix, + param, + enum_str); + MEM_freeN((void *)enum_str); + return -1; } return 0; @@ -1715,14 +1713,14 @@ static int pyrna_py_to_prop( Py_TYPE(value)->tp_name); return -1; } + + if (data) { + *((bool *)data) = param; + } else { - if (data) { - *((bool *)data) = param; - } - else { - RNA_property_boolean_set(ptr, prop, param); - } + RNA_property_boolean_set(ptr, prop, param); } + break; } case PROP_INT: { @@ -1737,7 +1735,7 @@ static int pyrna_py_to_prop( RNA_property_identifier(prop)); return -1; } - else if (param == -1 && PyErr_Occurred()) { + if (param == -1 && PyErr_Occurred()) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s expected an int type, not %.200s", error_prefix, @@ -1746,16 +1744,16 @@ static int pyrna_py_to_prop( Py_TYPE(value)->tp_name); return -1; } + + int param_i = (int)param; + if (data) { + RNA_property_int_clamp(ptr, prop, ¶m_i); + *((int *)data) = param_i; + } else { - int param_i = (int)param; - if (data) { - RNA_property_int_clamp(ptr, prop, ¶m_i); - *((int *)data) = param_i; - } - else { - RNA_property_int_set(ptr, prop, param_i); - } + RNA_property_int_set(ptr, prop, param_i); } + break; } case PROP_FLOAT: { @@ -1769,15 +1767,15 @@ static int pyrna_py_to_prop( Py_TYPE(value)->tp_name); return -1; } + + if (data) { + RNA_property_float_clamp(ptr, prop, (float *)¶m); + *((float *)data) = param; + } else { - if (data) { - RNA_property_float_clamp(ptr, prop, (float *)¶m); - *((float *)data) = param; - } - else { - RNA_property_float_set(ptr, prop, param); - } + RNA_property_float_set(ptr, prop, param); } + break; } case PROP_STRING: { @@ -1835,19 +1833,18 @@ static int pyrna_py_to_prop( return -1; } - else { - if (data) { - if (RNA_property_flag(prop) & PROP_THICK_WRAP) { - BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); - } - else { - *((char **)data) = (char *)param; - } + + if (data) { + if (RNA_property_flag(prop) & PROP_THICK_WRAP) { + BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); } else { - RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value)); + *((char **)data) = (char *)param; } } + else { + RNA_property_string_set_bytes(ptr, prop, param, PyBytes_Size(value)); + } } else { /* Unicode String. */ @@ -1886,22 +1883,22 @@ static int pyrna_py_to_prop( return -1; } - else { - /* Same as bytes. */ - /* XXX, this is suspect, but needed for function calls, - * need to see if there's a better way. */ - if (data) { - if (RNA_property_flag(prop) & PROP_THICK_WRAP) { - BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); - } - else { - *((char **)data) = (char *)param; - } + + /* Same as bytes. */ + /* XXX, this is suspect, but needed for function calls, + * need to see if there's a better way. */ + if (data) { + if (RNA_property_flag(prop) & PROP_THICK_WRAP) { + BLI_strncpy((char *)data, (char *)param, RNA_property_string_maxlength(prop)); } else { - RNA_property_string_set(ptr, prop, param); + *((char **)data) = (char *)param; } } + else { + RNA_property_string_set(ptr, prop, param); + } + #ifdef USE_STRING_COERCE Py_XDECREF(value_coerce); #endif /* USE_STRING_COERCE */ @@ -1971,7 +1968,7 @@ static int pyrna_py_to_prop( PointerRNA opptr = RNA_property_pointer_get(ptr, prop); return pyrna_pydict_to_props(&opptr, value, false, error_prefix); } - else if (base_type == &RNA_GizmoProperties) { + if (base_type == &RNA_GizmoProperties) { PointerRNA opptr = RNA_property_pointer_get(ptr, prop); return pyrna_pydict_to_props(&opptr, value, false, error_prefix); } @@ -2008,7 +2005,7 @@ static int pyrna_py_to_prop( Py_XDECREF(value_new); return -1; } - else if ((flag & PROP_NEVER_NULL) && value == Py_None) { + if ((flag & PROP_NEVER_NULL) && value == Py_None) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s does not support a 'None' assignment %.200s type", error_prefix, @@ -2018,8 +2015,8 @@ static int pyrna_py_to_prop( Py_XDECREF(value_new); return -1; } - else if ((value != Py_None) && ((flag & PROP_ID_SELF_CHECK) && - ptr->owner_id == ((BPy_StructRNA *)value)->ptr.owner_id)) { + if ((value != Py_None) && ((flag & PROP_ID_SELF_CHECK) && + ptr->owner_id == ((BPy_StructRNA *)value)->ptr.owner_id)) { PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s ID type does not support assignment to itself", error_prefix, @@ -2028,85 +2025,84 @@ static int pyrna_py_to_prop( Py_XDECREF(value_new); return -1; } - else { - BPy_StructRNA *param = (BPy_StructRNA *)value; - bool raise_error = false; - if (data) { - if (flag_parameter & PARM_RNAPTR) { - if (flag & PROP_THICK_WRAP) { - if (value == Py_None) { - memset(data, 0, sizeof(PointerRNA)); - } - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { - *((PointerRNA *)data) = param->ptr; - } - else { - raise_error = true; - } + BPy_StructRNA *param = (BPy_StructRNA *)value; + bool raise_error = false; + if (data) { + + if (flag_parameter & PARM_RNAPTR) { + if (flag & PROP_THICK_WRAP) { + if (value == Py_None) { + memset(data, 0, sizeof(PointerRNA)); + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { + *((PointerRNA *)data) = param->ptr; } else { - /* For function calls, we sometimes want to pass the 'ptr' directly, - * but watch out that it remains valid! - * We could possibly support this later if needed. */ - BLI_assert(value_new == NULL); - if (value == Py_None) { - *((void **)data) = NULL; - } - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { - *((PointerRNA **)data) = ¶m->ptr; - } - else { - raise_error = true; - } + raise_error = true; } } - else if (value == Py_None) { - *((void **)data) = NULL; - } - else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { - *((void **)data) = param->ptr.data; - } else { - raise_error = true; + /* For function calls, we sometimes want to pass the 'ptr' directly, + * but watch out that it remains valid! + * We could possibly support this later if needed. */ + BLI_assert(value_new == NULL); + if (value == Py_None) { + *((void **)data) = NULL; + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { + *((PointerRNA **)data) = ¶m->ptr; + } + else { + raise_error = true; + } } } + else if (value == Py_None) { + *((void **)data) = NULL; + } + else if (RNA_struct_is_a(param->ptr.type, ptr_type)) { + *((void **)data) = param->ptr.data; + } else { - /* Data == NULL, assign to RNA. */ - if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) { - ReportList reports; - BKE_reports_init(&reports, RPT_STORE); - RNA_property_pointer_set( - ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr, &reports); - int err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, true)); - if (err == -1) { - Py_XDECREF(value_new); - return -1; - } - } - else { - raise_error = true; + raise_error = true; + } + } + else { + /* Data == NULL, assign to RNA. */ + if (value == Py_None || RNA_struct_is_a(param->ptr.type, ptr_type)) { + ReportList reports; + BKE_reports_init(&reports, RPT_STORE); + RNA_property_pointer_set( + ptr, prop, value == Py_None ? PointerRNA_NULL : param->ptr, &reports); + int err = (BPy_reports_to_error(&reports, PyExc_RuntimeError, true)); + if (err == -1) { + Py_XDECREF(value_new); + return -1; } } + else { + raise_error = true; + } + } - if (raise_error) { - if (pyrna_struct_validity_check(param) == -1) { - /* Error set. */ - } - else { - PointerRNA tmp; - RNA_pointer_create(NULL, ptr_type, NULL, &tmp); - PyErr_Format(PyExc_TypeError, - "%.200s %.200s.%.200s expected a %.200s type, not %.200s", - error_prefix, - RNA_struct_identifier(ptr->type), - RNA_property_identifier(prop), - RNA_struct_identifier(tmp.type), - RNA_struct_identifier(param->ptr.type)); - } - Py_XDECREF(value_new); - return -1; + if (raise_error) { + if (pyrna_struct_validity_check(param) == -1) { + /* Error set. */ } + else { + PointerRNA tmp; + RNA_pointer_create(NULL, ptr_type, NULL, &tmp); + PyErr_Format(PyExc_TypeError, + "%.200s %.200s.%.200s expected a %.200s type, not %.200s", + error_prefix, + RNA_struct_identifier(ptr->type), + RNA_property_identifier(prop), + RNA_struct_identifier(tmp.type), + RNA_struct_identifier(param->ptr.type)); + } + Py_XDECREF(value_new); + return -1; } Py_XDECREF(value_new); @@ -2295,9 +2291,8 @@ static Py_ssize_t pyrna_prop_array_length(BPy_PropertyArrayRNA *self) if (RNA_property_array_dimension(&self->ptr, self->prop, NULL) > 1) { return RNA_property_multi_array_length(&self->ptr, self->prop, self->arraydim); } - else { - return RNA_property_array_length(&self->ptr, self->prop); - } + + return RNA_property_array_length(&self->ptr, self->prop); } static Py_ssize_t pyrna_prop_collection_length(BPy_PropertyRNA *self) @@ -2356,25 +2351,24 @@ static PyObject *pyrna_prop_collection_subscript_int(BPy_PropertyRNA *self, Py_s if (RNA_property_collection_lookup_int(&self->ptr, self->prop, keynum_abs, &newptr)) { return pyrna_struct_CreatePyObject(&newptr); } - else { - const int len = RNA_property_collection_length(&self->ptr, self->prop); - if (keynum_abs >= len) { - PyErr_Format(PyExc_IndexError, - "bpy_prop_collection[index]: " - "index %d out of range, size %d", - keynum, - len); - } - else { - PyErr_Format(PyExc_RuntimeError, - "bpy_prop_collection[index]: internal error, " - "valid index %d given in %d sized collection, but value not found", - keynum_abs, - len); - } - return NULL; + const int len = RNA_property_collection_length(&self->ptr, self->prop); + if (keynum_abs >= len) { + PyErr_Format(PyExc_IndexError, + "bpy_prop_collection[index]: " + "index %d out of range, size %d", + keynum, + len); + } + else { + PyErr_Format(PyExc_RuntimeError, + "bpy_prop_collection[index]: internal error, " + "valid index %d given in %d sized collection, but value not found", + keynum_abs, + len); } + + return NULL; } /* Values type must have been already checked. */ @@ -2473,79 +2467,76 @@ static int pyrna_prop_collection_subscript_str_lib_pair_ptr(BPy_PropertyRNA *sel PyTuple_GET_SIZE(key)); return -1; } - else if (self->ptr.type != &RNA_BlendData) { + if (self->ptr.type != &RNA_BlendData) { PyErr_Format(PyExc_KeyError, "%s: is only valid for bpy.data collections, not %.200s", err_prefix, RNA_struct_identifier(self->ptr.type)); return -1; } - else if ((keyname = _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) { + if ((keyname = _PyUnicode_AsString(PyTuple_GET_ITEM(key, 0))) == NULL) { PyErr_Format(PyExc_KeyError, "%s: id must be a string, not %.200s", err_prefix, Py_TYPE(PyTuple_GET_ITEM(key, 0))->tp_name); return -1; } - else { - PyObject *keylib = PyTuple_GET_ITEM(key, 1); - Library *lib; - bool found = false; - - if (keylib == Py_None) { - lib = NULL; - } - else if (PyUnicode_Check(keylib)) { - Main *bmain = self->ptr.data; - const char *keylib_str = _PyUnicode_AsString(keylib); - lib = BLI_findstring(&bmain->libraries, keylib_str, offsetof(Library, filepath)); - if (lib == NULL) { - if (err_not_found) { - PyErr_Format(PyExc_KeyError, - "%s: lib name '%.240s' " - "does not reference a valid library", - err_prefix, - keylib_str); - return -1; - } - else { - return 0; - } + + PyObject *keylib = PyTuple_GET_ITEM(key, 1); + Library *lib; + bool found = false; + + if (keylib == Py_None) { + lib = NULL; + } + else if (PyUnicode_Check(keylib)) { + Main *bmain = self->ptr.data; + const char *keylib_str = _PyUnicode_AsString(keylib); + lib = BLI_findstring(&bmain->libraries, keylib_str, offsetof(Library, filepath)); + if (lib == NULL) { + if (err_not_found) { + PyErr_Format(PyExc_KeyError, + "%s: lib name '%.240s' " + "does not reference a valid library", + err_prefix, + keylib_str); + return -1; } + + return 0; } - else { - PyErr_Format(PyExc_KeyError, - "%s: lib must be a string or None, not %.200s", - err_prefix, - Py_TYPE(keylib)->tp_name); - return -1; - } + } + else { + PyErr_Format(PyExc_KeyError, + "%s: lib must be a string or None, not %.200s", + err_prefix, + Py_TYPE(keylib)->tp_name); + return -1; + } - /* lib is either a valid pointer or NULL, - * either way can do direct comparison with id.lib */ + /* lib is either a valid pointer or NULL, + * either way can do direct comparison with id.lib */ - RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { - ID *id = itemptr.data; /* Always an ID. */ - if (id->lib == lib && (STREQLEN(keyname, id->name + 2, sizeof(id->name) - 2))) { - found = true; - if (r_ptr) { - *r_ptr = itemptr; - } - break; + RNA_PROP_BEGIN (&self->ptr, itemptr, self->prop) { + ID *id = itemptr.data; /* Always an ID. */ + if (id->lib == lib && (STREQLEN(keyname, id->name + 2, sizeof(id->name) - 2))) { + found = true; + if (r_ptr) { + *r_ptr = itemptr; } + break; } - RNA_PROP_END; + } + RNA_PROP_END; - /* We may want to fail silently as with collection.get(). */ - if ((found == false) && err_not_found) { - /* Only runs for getitem access so use fixed string. */ - PyErr_SetString(PyExc_KeyError, "bpy_prop_collection[key, lib]: not found"); - return -1; - } - else { - return found; /* 1 / 0, no exception. */ - } + /* We may want to fail silently as with collection.get(). */ + if ((found == false) && err_not_found) { + /* Only runs for getitem access so use fixed string. */ + PyErr_SetString(PyExc_KeyError, "bpy_prop_collection[key, lib]: not found"); + return -1; } + + return found; /* 1 / 0, no exception. */ } static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *self, @@ -2560,9 +2551,8 @@ static PyObject *pyrna_prop_collection_subscript_str_lib_pair(BPy_PropertyRNA *s if (contains == 1) { return pyrna_struct_CreatePyObject(&ptr); } - else { - return NULL; - } + + return NULL; } static PyObject *pyrna_prop_collection_subscript_slice(BPy_PropertyRNA *self, @@ -2707,7 +2697,7 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject if (PyUnicode_Check(key)) { return pyrna_prop_collection_subscript_str(self, _PyUnicode_AsString(key)); } - else if (PyIndex_Check(key)) { + if (PyIndex_Check(key)) { Py_ssize_t i = PyNumber_AsSsize_t(key, PyExc_IndexError); if (i == -1 && PyErr_Occurred()) { return NULL; @@ -2715,62 +2705,59 @@ static PyObject *pyrna_prop_collection_subscript(BPy_PropertyRNA *self, PyObject return pyrna_prop_collection_subscript_int(self, i); } - else if (PySlice_Check(key)) { + if (PySlice_Check(key)) { PySliceObject *key_slice = (PySliceObject *)key; Py_ssize_t step = 1; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; } - else if (step != 1) { + if (step != 1) { PyErr_SetString(PyExc_TypeError, "bpy_prop_collection[slice]: slice steps not supported"); return NULL; } - else if (key_slice->start == Py_None && key_slice->stop == Py_None) { + if (key_slice->start == Py_None && key_slice->stop == Py_None) { return pyrna_prop_collection_subscript_slice(self, 0, PY_SSIZE_T_MAX); } - else { - Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - /* Avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ - if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { - return NULL; - } - if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { - return NULL; - } + Py_ssize_t start = 0, stop = PY_SSIZE_T_MAX; - if (start < 0 || stop < 0) { - /* Only get the length for negative values. */ - Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); - if (start < 0) { - start += len; - } - if (stop < 0) { - stop += len; - } - } + /* Avoid PySlice_GetIndicesEx because it needs to know the length ahead of time. */ + if (key_slice->start != Py_None && !_PyEval_SliceIndex(key_slice->start, &start)) { + return NULL; + } + if (key_slice->stop != Py_None && !_PyEval_SliceIndex(key_slice->stop, &stop)) { + return NULL; + } - if (stop - start <= 0) { - return PyList_New(0); + if (start < 0 || stop < 0) { + /* Only get the length for negative values. */ + Py_ssize_t len = (Py_ssize_t)RNA_property_collection_length(&self->ptr, self->prop); + if (start < 0) { + start += len; } - else { - return pyrna_prop_collection_subscript_slice(self, start, stop); + if (stop < 0) { + stop += len; } } + + if (stop - start <= 0) { + return PyList_New(0); + } + + return pyrna_prop_collection_subscript_slice(self, start, stop); } - else if (PyTuple_Check(key)) { + if (PyTuple_Check(key)) { /* Special case, for ID datablocks we. */ return pyrna_prop_collection_subscript_str_lib_pair( self, key, "bpy_prop_collection[id, lib]", true); } - else { - PyErr_Format(PyExc_TypeError, - "bpy_prop_collection[key]: invalid key, " - "must be a string or an int, not %.200s", - Py_TYPE(key)->tp_name); - return NULL; - } + + PyErr_Format(PyExc_TypeError, + "bpy_prop_collection[key]: invalid key, " + "must be a string or an int, not %.200s", + Py_TYPE(key)->tp_name); + return NULL; } /* generic check to see if a PyObject is compatible with a collection @@ -2786,18 +2773,17 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val "this collection doesn't support None assignment"); return -1; } - else { - return 0; /* None is OK. */ - } + + return 0; /* None is OK. */ } - else if (BPy_StructRNA_Check(value) == 0) { + if (BPy_StructRNA_Check(value) == 0) { PyErr_Format(PyExc_TypeError, "bpy_prop_collection[key] = value: invalid, " "expected a StructRNA type or None, not a %.200s", Py_TYPE(value)->tp_name); return -1; } - else if ((prop_srna = RNA_property_pointer_type(&self->ptr, self->prop))) { + if ((prop_srna = RNA_property_pointer_type(&self->ptr, self->prop))) { StructRNA *value_srna = ((BPy_StructRNA *)value)->ptr.type; if (RNA_struct_is_a(value_srna, prop_srna) == 0) { PyErr_Format(PyExc_TypeError, @@ -2807,9 +2793,8 @@ static int pyrna_prop_collection_type_check(BPy_PropertyRNA *self, PyObject *val RNA_struct_identifier(value_srna)); return -1; } - else { - return 0; /* OK, this is the correct type! */ - } + + return 0; /* OK, this is the correct type! */ } PyErr_Format(PyExc_TypeError, @@ -2831,7 +2816,7 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, PyErr_SetString(PyExc_TypeError, "del bpy_prop_collection[key]: not supported"); return -1; } - else if (pyrna_prop_collection_type_check(self, value) == -1) { + if (pyrna_prop_collection_type_check(self, value) == -1) { return -1; /* Exception is set. */ } @@ -2895,13 +2880,12 @@ static int pyrna_prop_collection_ass_subscript(BPy_PropertyRNA *self, } } #endif - else { - PyErr_Format(PyExc_TypeError, - "bpy_prop_collection[key]: invalid key, " - "must be a string or an int, not %.200s", - Py_TYPE(key)->tp_name); - return -1; - } + + PyErr_Format(PyExc_TypeError, + "bpy_prop_collection[key]: invalid key, " + "must be a string or an int, not %.200s", + Py_TYPE(key)->tp_name); + return -1; } static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject *key) @@ -2921,43 +2905,40 @@ static PyObject *pyrna_prop_array_subscript(BPy_PropertyArrayRNA *self, PyObject } return pyrna_prop_array_subscript_int(self, i); } - else if (PySlice_Check(key)) { + if (PySlice_Check(key)) { Py_ssize_t step = 1; PySliceObject *key_slice = (PySliceObject *)key; if (key_slice->step != Py_None && !_PyEval_SliceIndex(key, &step)) { return NULL; } - else if (step != 1) { + if (step != 1) { PyErr_SetString(PyExc_TypeError, "bpy_prop_array[slice]: slice steps not supported"); return NULL; } - else if (key_slice->start == Py_None && key_slice->stop == Py_None) { + if (key_slice->start == Py_None && key_slice->stop == Py_None) { /* Note: no significant advantage with optimizing [:] slice as with collections, * but include here for consistency with collection slice func */ Py_ssize_t len = (Py_ssize_t)pyrna_prop_array_length(self); return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, 0, len, len); } - else { - int len = pyrna_prop_array_length(self); - Py_ssize_t start, stop, slicelength; - if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) { - return NULL; - } + int len = pyrna_prop_array_length(self); + Py_ssize_t start, stop, slicelength; - if (slicelength <= 0) { - return PyTuple_New(0); - } - else { - return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, start, stop, len); - } + if (PySlice_GetIndicesEx(key, len, &start, &stop, &step, &slicelength) < 0) { + return NULL; } + + if (slicelength <= 0) { + return PyTuple_New(0); + } + + return pyrna_prop_array_subscript_slice(self, &self->ptr, self->prop, start, stop, len); } - else { - PyErr_SetString(PyExc_AttributeError, "bpy_prop_array[key]: invalid key, key must be an int"); - return NULL; - } + + PyErr_SetString(PyExc_AttributeError, "bpy_prop_array[key]: invalid key, key must be an int"); + return NULL; } /** @@ -2972,7 +2953,7 @@ static PyObject *prop_subscript_ass_array_slice__as_seq_fast(PyObject *value, in "element in assignment is not a sequence type"))) { return NULL; } - else if (PySequence_Fast_GET_SIZE(value_fast) != length) { + if (PySequence_Fast_GET_SIZE(value_fast) != length) { Py_DECREF(value_fast); PyErr_SetString(PyExc_ValueError, "bpy_prop_array[slice] = value: " @@ -2980,9 +2961,8 @@ static PyObject *prop_subscript_ass_array_slice__as_seq_fast(PyObject *value, in return NULL; } - else { - return value_fast; - } + + return value_fast; } static int prop_subscript_ass_array_slice__float_recursive( @@ -3005,17 +2985,16 @@ static int prop_subscript_ass_array_slice__float_recursive( } return index; } - else { - BLI_assert(totdim == 1); - const float min = range[0], max = range[1]; - int i; - for (i = 0; i != length; i++) { - float v = PyFloat_AsDouble(value_items[i]); - CLAMP(v, min, max); - value[i] = v; - } - return i; + + BLI_assert(totdim == 1); + const float min = range[0], max = range[1]; + int i; + for (i = 0; i != length; i++) { + float v = PyFloat_AsDouble(value_items[i]); + CLAMP(v, min, max); + value[i] = v; } + return i; } static int prop_subscript_ass_array_slice__int_recursive( @@ -3038,17 +3017,16 @@ static int prop_subscript_ass_array_slice__int_recursive( } return index; } - else { - BLI_assert(totdim == 1); - const int min = range[0], max = range[1]; - int i; - for (i = 0; i != length; i++) { - int v = PyLong_AsLong(value_items[i]); - CLAMP(v, min, max); - value[i] = v; - } - return i; + + BLI_assert(totdim == 1); + const int min = range[0], max = range[1]; + int i; + for (i = 0; i != length; i++) { + int v = PyLong_AsLong(value_items[i]); + CLAMP(v, min, max); + value[i] = v; } + return i; } static int prop_subscript_ass_array_slice__bool_recursive(PyObject **value_items, @@ -3073,15 +3051,14 @@ static int prop_subscript_ass_array_slice__bool_recursive(PyObject **value_items } return index; } - else { - BLI_assert(totdim == 1); - int i; - for (i = 0; i != length; i++) { - int v = PyLong_AsLong(value_items[i]); - value[i] = v; - } - return i; + + BLI_assert(totdim == 1); + int i; + for (i = 0; i != length; i++) { + int v = PyLong_AsLong(value_items[i]); + value[i] = v; } + return i; } /* Could call `pyrna_py_to_prop_array_index(self, i, value)` in a loop, but it is slow. */ @@ -3364,23 +3341,21 @@ static int pyrna_prop_collection_contains(BPy_PropertyRNA *self, PyObject *key) return pyrna_prop_collection_subscript_str_lib_pair_ptr( self, key, "(id, lib) in bpy_prop_collection", false, NULL); } - else { - - /* Key in dict style check. */ - const char *keyname = _PyUnicode_AsString(key); - if (keyname == NULL) { - PyErr_SetString(PyExc_TypeError, - "bpy_prop_collection.__contains__: expected a string or a tuple of strings"); - return -1; - } + /* Key in dict style check. */ + const char *keyname = _PyUnicode_AsString(key); - if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { - return 1; - } + if (keyname == NULL) { + PyErr_SetString(PyExc_TypeError, + "bpy_prop_collection.__contains__: expected a string or a tuple of strings"); + return -1; + } - return 0; + if (RNA_property_collection_lookup_string(&self->ptr, self->prop, keyname, &newptr)) { + return 1; } + + return 0; } static int pyrna_struct_contains(BPy_StructRNA *self, PyObject *value) @@ -3821,30 +3796,25 @@ static PyObject *pyrna_struct_path_resolve(BPy_StructRNA *self, PyObject *args) path); return NULL; } - else { - return pyrna_array_index(&r_ptr, r_prop, index); - } + + return pyrna_array_index(&r_ptr, r_prop, index); } - else { - if (coerce == Py_False) { - return pyrna_prop_CreatePyObject(&r_ptr, r_prop); - } - else { - return pyrna_prop_to_py(&r_ptr, r_prop); - } + + if (coerce == Py_False) { + return pyrna_prop_CreatePyObject(&r_ptr, r_prop); } + + return pyrna_prop_to_py(&r_ptr, r_prop); } - else { - return pyrna_struct_CreatePyObject(&r_ptr); - } - } - else { - PyErr_Format(PyExc_ValueError, - "%.200s.path_resolve(\"%.200s\") could not be resolved", - RNA_struct_identifier(self->ptr.type), - path); - return NULL; + + return pyrna_struct_CreatePyObject(&r_ptr); } + + PyErr_Format(PyExc_ValueError, + "%.200s.path_resolve(\"%.200s\") could not be resolved", + RNA_struct_identifier(self->ptr.type), + path); + return NULL; } PyDoc_STRVAR(pyrna_struct_path_from_id_doc, @@ -3954,22 +3924,21 @@ static PyObject *pyrna_prop_as_bytes(BPy_PropertyRNA *self) RNA_property_identifier(self->prop)); return NULL; } - else { - PyObject *ret; - char buf_fixed[256], *buf; - int buf_len; - buf = RNA_property_string_get_alloc( - &self->ptr, self->prop, buf_fixed, sizeof(buf_fixed), &buf_len); + PyObject *ret; + char buf_fixed[256], *buf; + int buf_len; - ret = PyBytes_FromStringAndSize(buf, buf_len); + buf = RNA_property_string_get_alloc( + &self->ptr, self->prop, buf_fixed, sizeof(buf_fixed), &buf_len); - if (buf_fixed != buf) { - MEM_freeN(buf); - } + ret = PyBytes_FromStringAndSize(buf, buf_len); - return ret; + if (buf_fixed != buf) { + MEM_freeN(buf); } + + return ret; } PyDoc_STRVAR(pyrna_prop_update_doc, @@ -4478,7 +4447,7 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject PyErr_SetString(PyExc_AttributeError, "bpy_struct: __setattr__ must be a string"); return -1; } - else if (name[0] != '_' && (prop = RNA_struct_find_property(&self->ptr, name))) { + if (name[0] != '_' && (prop = RNA_struct_find_property(&self->ptr, name))) { if (!RNA_property_editable_flag(&self->ptr, prop)) { PyErr_Format(PyExc_AttributeError, "bpy_struct: attribute \"%.200s\" from \"%.200s\" is read-only", @@ -4497,22 +4466,21 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject name); return -1; } - else { - PointerRNA newptr; - ListBase newlb; - short newtype; - int done = CTX_data_get(C, name, &newptr, &newlb, &newtype); + PointerRNA newptr; + ListBase newlb; + short newtype; - if (done == 1) { - PyErr_Format( - PyExc_AttributeError, "bpy_struct: Context property \"%.200s\" is read-only", name); - BLI_freelistN(&newlb); - return -1; - } + int done = CTX_data_get(C, name, &newptr, &newlb, &newtype); + if (done == 1) { + PyErr_Format( + PyExc_AttributeError, "bpy_struct: Context property \"%.200s\" is read-only", name); BLI_freelistN(&newlb); + return -1; } + + BLI_freelistN(&newlb); } /* pyrna_py_to_prop sets its own exceptions */ @@ -4523,9 +4491,8 @@ static int pyrna_struct_setattro(BPy_StructRNA *self, PyObject *pyname, PyObject } return pyrna_py_to_prop(&self->ptr, prop, NULL, value, "bpy_struct: item.attr = val:"); } - else { - return PyObject_GenericSetAttr((PyObject *)self, pyname, value); - } + + return PyObject_GenericSetAttr((PyObject *)self, pyname, value); } static PyObject *pyrna_prop_dir(BPy_PropertyRNA *self) @@ -4563,7 +4530,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject PyErr_SetString(PyExc_AttributeError, "bpy_prop_collection: __getattr__ must be a string"); return NULL; } - else if (name[0] != '_') { + if (name[0] != '_') { PyObject *ret; PropertyRNA *prop; FunctionRNA *func; @@ -4575,7 +4542,7 @@ static PyObject *pyrna_prop_collection_getattro(BPy_PropertyRNA *self, PyObject return ret; } - else if ((func = RNA_struct_find_function(r_ptr.type, name))) { + if ((func = RNA_struct_find_function(r_ptr.type, name))) { PyObject *self_collection = pyrna_struct_CreatePyObject(&r_ptr); ret = pyrna_func_to_py(&((BPy_DummyPointerRNA *)self_collection)->ptr, func); Py_DECREF(self_collection); @@ -4639,11 +4606,11 @@ static int pyrna_prop_collection_setattro(BPy_PropertyRNA *self, PyObject *pynam PyErr_SetString(PyExc_AttributeError, "bpy_prop: __setattr__ must be a string"); return -1; } - else if (value == NULL) { + if (value == NULL) { PyErr_SetString(PyExc_AttributeError, "bpy_prop: del not supported"); return -1; } - else if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { + if (RNA_property_collection_type_get(&self->ptr, self->prop, &r_ptr)) { if ((prop = RNA_struct_find_property(&r_ptr, name))) { /* pyrna_py_to_prop sets its own exceptions. */ return pyrna_py_to_prop(&r_ptr, prop, NULL, value, "BPy_PropertyRNA - Attribute (setattr):"); @@ -4673,9 +4640,8 @@ static PyObject *pyrna_prop_collection_idprop_add(BPy_PropertyRNA *self) "bpy_prop_collection.add(): not supported for this collection"); return NULL; } - else { - return pyrna_struct_CreatePyObject(&r_ptr); - } + + return pyrna_struct_CreatePyObject(&r_ptr); } static PyObject *pyrna_prop_collection_idprop_remove(BPy_PropertyRNA *self, PyObject *value) @@ -5798,7 +5764,7 @@ static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject * Py_INCREF(base); return (PyObject *)base; } - else if (PyType_IsSubtype(Py_TYPE(base), &pyrna_struct_Type)) { + if (PyType_IsSubtype(Py_TYPE(base), &pyrna_struct_Type)) { /* this almost never runs, only when using user defined subclasses of built-in object. * this isn't common since it's NOT related to registerable subclasses. eg: * @@ -5826,10 +5792,9 @@ static PyObject *pyrna_struct_new(PyTypeObject *type, PyObject *args, PyObject * type->tp_name); return NULL; } - else { - PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): expected a single argument"); - return NULL; - } + + PyErr_Format(PyExc_TypeError, "bpy_struct.__new__(type): expected a single argument"); + return NULL; } /* only needed for subtyping, so a new class gets a valid BPy_StructRNA @@ -5845,18 +5810,17 @@ static PyObject *pyrna_prop_new(PyTypeObject *type, PyObject *args, PyObject *UN if (type == Py_TYPE(base)) { return Py_INCREF_RET((PyObject *)base); } - else if (PyType_IsSubtype(type, &pyrna_prop_Type)) { + if (PyType_IsSubtype(type, &pyrna_prop_Type)) { BPy_PropertyRNA *ret = (BPy_PropertyRNA *)type->tp_alloc(type, 0); ret->ptr = base->ptr; ret->prop = base->prop; return (PyObject *)ret; } - else { - PyErr_Format(PyExc_TypeError, - "bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop", - type->tp_name); - return NULL; - } + + PyErr_Format(PyExc_TypeError, + "bpy_prop.__new__(type): type '%.200s' is not a subtype of bpy_prop", + type->tp_name); + return NULL; } static PyObject *pyrna_param_to_py(PointerRNA *ptr, PropertyRNA *prop, void *data) @@ -6192,9 +6156,8 @@ static PyObject *pyrna_func_call(BPy_FunctionRNA *self, PyObject *args, PyObject err = -1; break; } - else { /* PyDict_GetItemString wont raise an error. */ - continue; - } + /* PyDict_GetItemString wont raise an error. */ + continue; } #ifdef DEBUG_STRING_FREE @@ -7131,25 +7094,24 @@ static PyObject *pyrna_prop_collection_iter_next(BPy_PropertyCollectionIterRNA * PyErr_SetNone(PyExc_StopIteration); return NULL; } - else { - BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr); + + BPy_StructRNA *pyrna = (BPy_StructRNA *)pyrna_struct_CreatePyObject(&self->iter.ptr); # ifdef USE_PYRNA_STRUCT_REFERENCE - if (pyrna) { /* Unlikely, but may fail. */ - if ((PyObject *)pyrna != Py_None) { - /* hold a reference to the iterator since it may have - * allocated memory 'pyrna' needs. eg: introspecting dynamic enum's */ - /* TODO, we could have an api call to know if this is - * needed since most collections don't */ - pyrna_struct_reference_set(pyrna, (PyObject *)self); - } + if (pyrna) { /* Unlikely, but may fail. */ + if ((PyObject *)pyrna != Py_None) { + /* hold a reference to the iterator since it may have + * allocated memory 'pyrna' needs. eg: introspecting dynamic enum's */ + /* TODO, we could have an api call to know if this is + * needed since most collections don't */ + pyrna_struct_reference_set(pyrna, (PyObject *)self); } + } # endif /* !USE_PYRNA_STRUCT_REFERENCE */ - RNA_property_collection_next(&self->iter); + RNA_property_collection_next(&self->iter); - return (PyObject *)pyrna; - } + return (PyObject *)pyrna; } static void pyrna_prop_collection_iter_dealloc(BPy_PropertyCollectionIterRNA *self) @@ -7413,9 +7375,8 @@ static StructRNA *srna_from_ptr(PointerRNA *ptr) if (ptr->type == &RNA_Struct) { return ptr->data; } - else { - return ptr->type; - } + + return ptr->type; } /* Always returns a new ref, be sure to decref when done. */ @@ -7445,15 +7406,14 @@ PyObject *pyrna_struct_CreatePyObject(PointerRNA *ptr) Py_INCREF(pyrna); return (PyObject *)pyrna; } - else { - /* Existing users will need to use 'type_recast' method. */ - Py_DECREF(pyrna); - *instance = NULL; - /* Continue as if no instance was made. */ + + /* Existing users will need to use 'type_recast' method. */ + Py_DECREF(pyrna); + *instance = NULL; + /* Continue as if no instance was made. */ #if 0 /* No need to assign, will be written to next... */ pyrna = NULL; #endif - } } { @@ -7560,9 +7520,8 @@ PyObject *pyrna_id_CreatePyObject(ID *id) RNA_id_pointer_create(id, &ptr); return pyrna_struct_CreatePyObject(&ptr); } - else { - Py_RETURN_NONE; - } + + Py_RETURN_NONE; } bool pyrna_id_FromPyObject(PyObject *obj, ID **id) @@ -7571,10 +7530,9 @@ bool pyrna_id_FromPyObject(PyObject *obj, ID **id) *id = ((BPy_StructRNA *)obj)->ptr.owner_id; return true; } - else { - *id = NULL; - return false; - } + + *id = NULL; + return false; } bool pyrna_id_CheckPyObject(PyObject *obj) @@ -7869,30 +7827,29 @@ StructRNA *srna_from_self(PyObject *self, const char *error_prefix) if (self == NULL) { return NULL; } - else if (PyCapsule_CheckExact(self)) { + if (PyCapsule_CheckExact(self)) { return PyCapsule_GetPointer(self, NULL); } - else if (PyType_Check(self) == 0) { + if (PyType_Check(self) == 0) { return NULL; } - else { - /* These cases above not errors, they just mean the type was not compatible - * After this any errors will be raised in the script */ - PyObject *error_type, *error_value, *error_traceback; - StructRNA *srna; + /* These cases above not errors, they just mean the type was not compatible + * After this any errors will be raised in the script */ - PyErr_Fetch(&error_type, &error_value, &error_traceback); - PyErr_Clear(); + PyObject *error_type, *error_value, *error_traceback; + StructRNA *srna; - srna = pyrna_struct_as_srna(self, false, error_prefix); + PyErr_Fetch(&error_type, &error_value, &error_traceback); + PyErr_Clear(); - if (!PyErr_Occurred()) { - PyErr_Restore(error_type, error_value, error_traceback); - } + srna = pyrna_struct_as_srna(self, false, error_prefix); - return srna; + if (!PyErr_Occurred()) { + PyErr_Restore(error_type, error_value, error_traceback); } + + return srna; } static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item) -- cgit v1.2.3