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.
This commit is contained in:
@@ -415,10 +415,9 @@ typedef struct BufferOrOffset {
|
||||
if (ret_str) { \
|
||||
return PyUnicode_FromString((const char *)ret_str); \
|
||||
} \
|
||||
else { \
|
||||
PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \
|
||||
return NULL; \
|
||||
}
|
||||
\
|
||||
PyErr_SetString(PyExc_AttributeError, "could not get opengl string"); \
|
||||
return NULL;
|
||||
|
||||
/** \} */
|
||||
|
||||
@@ -705,7 +704,7 @@ static int BGL_BufferOrOffsetConverter(PyObject *object, BufferOrOffset *buffer)
|
||||
buffer->offset = NULL;
|
||||
return 1;
|
||||
}
|
||||
else if (PyNumber_Check(object)) {
|
||||
if (PyNumber_Check(object)) {
|
||||
Py_ssize_t offset = PyNumber_AsSsize_t(object, PyExc_IndexError);
|
||||
if (offset == -1 && PyErr_Occurred()) {
|
||||
return 0;
|
||||
@@ -715,15 +714,14 @@ static int BGL_BufferOrOffsetConverter(PyObject *object, BufferOrOffset *buffer)
|
||||
buffer->offset = (void *)offset;
|
||||
return 1;
|
||||
}
|
||||
else if (PyObject_TypeCheck(object, &BGL_bufferType)) {
|
||||
if (PyObject_TypeCheck(object, &BGL_bufferType)) {
|
||||
buffer->buffer = (Buffer *)object;
|
||||
buffer->offset = NULL;
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "expected a bgl.Buffer or None");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "expected a bgl.Buffer or None");
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define MAX_DIMENSIONS 256
|
||||
@@ -766,7 +764,7 @@ static PyObject *Buffer_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject
|
||||
"too many dimensions, max is " STRINGIFY(MAX_DIMENSIONS));
|
||||
return NULL;
|
||||
}
|
||||
else if (ndimensions < 1) {
|
||||
if (ndimensions < 1) {
|
||||
PyErr_SetString(PyExc_AttributeError, "sequence must have at least one dimension");
|
||||
return NULL;
|
||||
}
|
||||
@@ -913,9 +911,8 @@ static int Buffer_ass_item(Buffer *self, int i, PyObject *v)
|
||||
Py_DECREF(row);
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (self->type) {
|
||||
@@ -996,7 +993,7 @@ static PyObject *Buffer_subscript(Buffer *self, PyObject *item)
|
||||
}
|
||||
return Buffer_item(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -1006,19 +1003,17 @@ static PyObject *Buffer_subscript(Buffer *self, PyObject *item)
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return Buffer_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value)
|
||||
@@ -1033,7 +1028,7 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value)
|
||||
}
|
||||
return Buffer_ass_item(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->dimensions[0], &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -1043,16 +1038,14 @@ static int Buffer_ass_subscript(Buffer *self, PyObject *item, PyObject *value)
|
||||
if (step == 1) {
|
||||
return Buffer_ass_slice(self, start, stop, value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "buffer indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void Buffer_dealloc(Buffer *self)
|
||||
|
||||
@@ -51,13 +51,12 @@ static PyObject *idprop_py_from_idp_string(const IDProperty *prop)
|
||||
if (prop->subtype == IDP_STRING_SUB_BYTE) {
|
||||
return PyBytes_FromStringAndSize(IDP_String(prop), prop->len);
|
||||
}
|
||||
else {
|
||||
|
||||
#ifdef USE_STRING_COERCE
|
||||
return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
|
||||
return PyC_UnicodeFromByteAndSize(IDP_Array(prop), prop->len - 1);
|
||||
#else
|
||||
return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1);
|
||||
return PyUnicode_FromStringAndSize(IDP_String(prop), prop->len - 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *idprop_py_from_idp_int(const IDProperty *prop)
|
||||
@@ -479,10 +478,10 @@ static IDProperty *idp_from_PySequence_Buffer(const char *name, Py_buffer *buffe
|
||||
/* should never happen as the type has been checked before */
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
val.array.type = id_type;
|
||||
val.array.len = buffer->len / buffer->itemsize;
|
||||
}
|
||||
|
||||
val.array.type = id_type;
|
||||
val.array.len = buffer->len / buffer->itemsize;
|
||||
|
||||
prop = IDP_New(IDP_ARRAY, &val, name);
|
||||
memcpy(IDP_Array(prop), buffer->buf, buffer->len);
|
||||
return prop;
|
||||
@@ -576,17 +575,15 @@ static IDProperty *idp_from_PySequence(const char *name, PyObject *ob)
|
||||
PyBuffer_Release(&buffer);
|
||||
return prop;
|
||||
}
|
||||
else {
|
||||
PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop");
|
||||
if (ob_seq_fast != NULL) {
|
||||
IDProperty *prop = idp_from_PySequence_Fast(name, ob_seq_fast);
|
||||
Py_DECREF(ob_seq_fast);
|
||||
return prop;
|
||||
}
|
||||
else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *ob_seq_fast = PySequence_Fast(ob, "py -> idprop");
|
||||
if (ob_seq_fast != NULL) {
|
||||
IDProperty *prop = idp_from_PySequence_Fast(name, ob_seq_fast);
|
||||
Py_DECREF(ob_seq_fast);
|
||||
return prop;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob)
|
||||
@@ -641,29 +638,28 @@ static IDProperty *idp_from_PyObject(PyObject *name_obj, PyObject *ob)
|
||||
if (PyFloat_Check(ob)) {
|
||||
return idp_from_PyFloat(name, ob);
|
||||
}
|
||||
else if (PyLong_Check(ob)) {
|
||||
if (PyLong_Check(ob)) {
|
||||
return idp_from_PyLong(name, ob);
|
||||
}
|
||||
else if (PyUnicode_Check(ob)) {
|
||||
if (PyUnicode_Check(ob)) {
|
||||
return idp_from_PyUnicode(name, ob);
|
||||
}
|
||||
else if (PyBytes_Check(ob)) {
|
||||
if (PyBytes_Check(ob)) {
|
||||
return idp_from_PyBytes(name, ob);
|
||||
}
|
||||
else if (PySequence_Check(ob)) {
|
||||
if (PySequence_Check(ob)) {
|
||||
return idp_from_PySequence(name, ob);
|
||||
}
|
||||
else if (ob == Py_None || pyrna_id_CheckPyObject(ob)) {
|
||||
if (ob == Py_None || pyrna_id_CheckPyObject(ob)) {
|
||||
return idp_from_DatablockPointer(name, ob);
|
||||
}
|
||||
else if (PyMapping_Check(ob)) {
|
||||
if (PyMapping_Check(ob)) {
|
||||
return idp_from_PyMapping(name, ob);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "invalid id-property type %.200s not supported", Py_TYPE(ob)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "invalid id-property type %.200s not supported", Py_TYPE(ob)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
@@ -736,21 +732,19 @@ int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
|
||||
IDP_FreeFromGroup(prop, pkey);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_KeyError, "property not found in group");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
bool ok;
|
||||
|
||||
ok = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val);
|
||||
if (ok == false) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
PyErr_SetString(PyExc_KeyError, "property not found in group");
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool ok;
|
||||
|
||||
ok = BPy_IDProperty_Map_ValidateAndCreate(key, prop, val);
|
||||
if (ok == false) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int BPy_IDGroup_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *val)
|
||||
@@ -1485,7 +1479,7 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item)
|
||||
}
|
||||
return BPy_IDArray_GetItem(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -1495,21 +1489,19 @@ static PyObject *BPy_IDArray_subscript(BPy_IDArray *self, PyObject *item)
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return BPy_IDArray_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"vector indices must be integers, not %.200s",
|
||||
__func__,
|
||||
Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"vector indices must be integers, not %.200s",
|
||||
__func__,
|
||||
Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject *value)
|
||||
@@ -1524,7 +1516,7 @@ static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject
|
||||
}
|
||||
return BPy_IDArray_SetItem(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->prop->len, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -1534,16 +1526,14 @@ static int BPy_IDArray_ass_subscript(BPy_IDArray *self, PyObject *item, PyObject
|
||||
if (step == 1) {
|
||||
return BPy_IDArray_ass_slice(self, start, stop, value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_TypeError, "slice steps not supported with vectors");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PyMappingMethods BPy_IDArray_AsMapping = {
|
||||
@@ -1709,14 +1699,12 @@ static PyObject *BPy_Group_Iter_Next(BPy_IDGroup_Iter *self)
|
||||
BPy_IDGroup_WrapData(self->group->id, cur, self->group->prop));
|
||||
return ret;
|
||||
}
|
||||
else {
|
||||
return PyUnicode_FromString(cur->name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_SetNone(PyExc_StopIteration);
|
||||
return NULL;
|
||||
|
||||
return PyUnicode_FromString(cur->name);
|
||||
}
|
||||
|
||||
PyErr_SetNone(PyExc_StopIteration);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyTypeObject BPy_IDGroup_Iter_Type = {
|
||||
|
||||
@@ -57,11 +57,10 @@ static int py_imbuf_valid_check(Py_ImBuf *self)
|
||||
if (LIKELY(self->ibuf)) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_ReferenceError, "ImBuf data of type %.200s has been freed", Py_TYPE(self)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_ReferenceError, "ImBuf data of type %.200s has been freed", Py_TYPE(self)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
#define PY_IMBUF_CHECK_OBJ(obj) \
|
||||
@@ -324,9 +323,8 @@ static PyObject *py_imbuf_repr(Py_ImBuf *self)
|
||||
return PyUnicode_FromFormat(
|
||||
"<imbuf: address=%p, filepath='%s', size=(%d, %d)>", ibuf, ibuf->name, ibuf->x, ibuf->y);
|
||||
}
|
||||
else {
|
||||
return PyUnicode_FromString("<imbuf: address=0x0>");
|
||||
}
|
||||
|
||||
return PyUnicode_FromString("<imbuf: address=0x0>");
|
||||
}
|
||||
|
||||
static Py_hash_t py_imbuf_hash(Py_ImBuf *self)
|
||||
|
||||
@@ -375,12 +375,11 @@ void PyC_StackSpit(void)
|
||||
fprintf(stderr, "python line lookup failed, interpreter inactive\n");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
/* lame but handy */
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
PyRun_SimpleString("__import__('traceback').print_stack()");
|
||||
PyGILState_Release(gilstate);
|
||||
}
|
||||
|
||||
/* lame but handy */
|
||||
PyGILState_STATE gilstate = PyGILState_Ensure();
|
||||
PyRun_SimpleString("__import__('traceback').print_stack()");
|
||||
PyGILState_Release(gilstate);
|
||||
}
|
||||
|
||||
void PyC_StackPrint(/* FILE */ void *fp)
|
||||
@@ -760,22 +759,20 @@ const char *PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObjec
|
||||
* chars since blender doesn't limit this */
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
|
||||
if (PyBytes_Check(py_str)) {
|
||||
*size = PyBytes_GET_SIZE(py_str);
|
||||
return PyBytes_AS_STRING(py_str);
|
||||
}
|
||||
else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
|
||||
*size = PyBytes_GET_SIZE(*coerce);
|
||||
return PyBytes_AS_STRING(*coerce);
|
||||
}
|
||||
else {
|
||||
/* leave error raised from EncodeFS */
|
||||
return NULL;
|
||||
}
|
||||
PyErr_Clear();
|
||||
|
||||
if (PyBytes_Check(py_str)) {
|
||||
*size = PyBytes_GET_SIZE(py_str);
|
||||
return PyBytes_AS_STRING(py_str);
|
||||
}
|
||||
if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
|
||||
*size = PyBytes_GET_SIZE(*coerce);
|
||||
return PyBytes_AS_STRING(*coerce);
|
||||
}
|
||||
|
||||
/* leave error raised from EncodeFS */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
||||
@@ -789,20 +786,18 @@ const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
|
||||
* chars since blender doesn't limit this. */
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
|
||||
if (PyBytes_Check(py_str)) {
|
||||
return PyBytes_AS_STRING(py_str);
|
||||
}
|
||||
else if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
|
||||
return PyBytes_AS_STRING(*coerce);
|
||||
}
|
||||
else {
|
||||
/* leave error raised from EncodeFS */
|
||||
return NULL;
|
||||
}
|
||||
PyErr_Clear();
|
||||
|
||||
if (PyBytes_Check(py_str)) {
|
||||
return PyBytes_AS_STRING(py_str);
|
||||
}
|
||||
if ((*coerce = PyUnicode_EncodeFSDefault(py_str))) {
|
||||
return PyBytes_AS_STRING(*coerce);
|
||||
}
|
||||
|
||||
/* leave error raised from EncodeFS */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
|
||||
@@ -813,12 +808,11 @@ PyObject *PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size)
|
||||
* chars since blender doesn't limit this */
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
PyErr_Clear();
|
||||
/* this means paths will always be accessible once converted, on all OS's */
|
||||
result = PyUnicode_DecodeFSDefaultAndSize(str, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
PyErr_Clear();
|
||||
/* this means paths will always be accessible once converted, on all OS's */
|
||||
result = PyUnicode_DecodeFSDefaultAndSize(str, size);
|
||||
return result;
|
||||
}
|
||||
|
||||
PyObject *PyC_UnicodeFromByte(const char *str)
|
||||
@@ -1136,13 +1130,12 @@ void *PyC_RNA_AsPointer(PyObject *value, const char *type_name)
|
||||
|
||||
return result;
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expected '%.200s' type found '%.200s' instead",
|
||||
type_name,
|
||||
Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"expected '%.200s' type found '%.200s' instead",
|
||||
type_name,
|
||||
Py_TYPE(value)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
||||
Reference in New Issue
Block a user