Commit: ce68888d1bfe9ecae72207a9082c327fda07bce1
Author: Campbell Barton
Date:   Wed Jul 28 12:45:44 2021 +1000
Branches: master
https://developer.blender.org/rBce68888d1bfe9ecae72207a9082c327fda07bce1

Cleanup: reduce indentation in bpy.props

Remove unnecessary NULL checks.

===================================================================

M       source/blender/python/intern/bpy_props.c

===================================================================

diff --git a/source/blender/python/intern/bpy_props.c 
b/source/blender/python/intern/bpy_props.c
index c6d81c788ff..b63e7863f79 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -2231,27 +2231,33 @@ static void bpy_prop_callback_assign_enum(struct 
PropertyRNA *prop,
 /** \name Shared Method Utilities
  * \{ */
 
-/* this define runs at the start of each function and deals with
- * returning a deferred property (to be registered later) */
+/**
+ * This define runs at the start of each function and deals with
+ * returning a deferred property #BPy_PropDeferred (to be registered later).
+ *
+ * \note `srna` will always be left set if this function doesn't return.
+ */
 #define BPY_PROPDEF_HEAD(_func) \
-  if (PyTuple_GET_SIZE(args) == 1) { \
-    PyObject *ret; \
-    self = PyTuple_GET_ITEM(args, 0); \
-    args = PyTuple_New(0); \
-    ret = BPy_##_func(self, args, kw); \
-    Py_DECREF(args); \
-    return ret; \
-  } \
-  if (PyTuple_GET_SIZE(args) > 1) { \
-    PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
-    return NULL; \
-  } \
-  srna = srna_from_self(self, #_func "(...):"); \
-  if (srna == NULL) { \
-    if (PyErr_Occurred()) { \
+  { \
+    const int args_len = PyTuple_GET_SIZE(args); \
+    if (args_len == 1) { \
+      self = PyTuple_GET_ITEM(args, 0); \
+      args = PyTuple_New(0); \
+      PyObject *ret = BPy_##_func(self, args, kw); \
+      Py_DECREF(args); \
+      return ret; \
+    } \
+    if (args_len > 1) { \
+      PyErr_SetString(PyExc_ValueError, "all args must be keywords"); \
       return NULL; \
     } \
-    return bpy_prop_deferred_data_CreatePyObject(pymeth_##_func, kw); \
+    srna = srna_from_self(self, #_func "(...):"); \
+    if (srna == NULL) { \
+      if (PyErr_Occurred()) { \
+        return NULL; \
+      } \
+      return bpy_prop_deferred_data_CreatePyObject(pymeth_##_func, kw); \
+    } \
   } \
   (void)0
 
@@ -2430,96 +2436,95 @@ PyDoc_STRVAR(BPy_BoolProperty_doc,
                          BPY_PROPDEF_SET_DOC);
 static PyObject *BPy_BoolProperty(PyObject *self, PyObject *args, PyObject *kw)
 {
+  /* Keep this block first. */
   StructRNA *srna;
-
   BPY_PROPDEF_HEAD(BoolProperty);
+  BLI_assert(srna != NULL);
+
+  const char *id = NULL, *name = NULL, *description = "";
+  Py_ssize_t id_len;
+  bool def = false;
+  PropertyRNA *prop;
+  PyObject *pyopts = NULL;
+  PyObject *pyopts_override = NULL;
+  int opts = 0;
+  int opts_override = 0;
+  int prop_tags = 0;
+  const char *pysubtype = NULL;
+  int subtype = PROP_NONE;
+  PyObject *update_fn = NULL;
+  PyObject *get_fn = NULL;
+  PyObject *set_fn = NULL;
+  PyObject *py_tags = NULL;
 
-  if (srna) {
-    const char *id = NULL, *name = NULL, *description = "";
-    Py_ssize_t id_len;
-    bool def = false;
-    PropertyRNA *prop;
-    PyObject *pyopts = NULL;
-    PyObject *pyopts_override = NULL;
-    int opts = 0;
-    int opts_override = 0;
-    int prop_tags = 0;
-    const char *pysubtype = NULL;
-    int subtype = PROP_NONE;
-    PyObject *update_fn = NULL;
-    PyObject *get_fn = NULL;
-    PyObject *set_fn = NULL;
-    PyObject *py_tags = NULL;
-
-    static const char *_keywords[] = {
-        "attr",
-        "name",
-        "description",
-        "default",
-        "options",
-        "override",
-        "tags",
-        "subtype",
-        "update",
-        "get",
-        "set",
-        NULL,
-    };
-    static _PyArg_Parser _parser = {"s#|$ssO&O!O!O!sOOO:BoolProperty", 
_keywords, 0};
-    if (!_PyArg_ParseTupleAndKeywordsFast(args,
-                                          kw,
-                                          &_parser,
-                                          &id,
-                                          &id_len,
-                                          &name,
-                                          &description,
-                                          PyC_ParseBool,
-                                          &def,
-                                          &PySet_Type,
-                                          &pyopts,
-                                          &PySet_Type,
-                                          &pyopts_override,
-                                          &PySet_Type,
-                                          &py_tags,
-                                          &pysubtype,
-                                          &update_fn,
-                                          &get_fn,
-                                          &set_fn)) {
-      return NULL;
-    }
+  static const char *_keywords[] = {
+      "attr",
+      "name",
+      "description",
+      "default",
+      "options",
+      "override",
+      "tags",
+      "subtype",
+      "update",
+      "get",
+      "set",
+      NULL,
+  };
+  static _PyArg_Parser _parser = {"s#|$ssO&O!O!O!sOOO:BoolProperty", 
_keywords, 0};
+  if (!_PyArg_ParseTupleAndKeywordsFast(args,
+                                        kw,
+                                        &_parser,
+                                        &id,
+                                        &id_len,
+                                        &name,
+                                        &description,
+                                        PyC_ParseBool,
+                                        &def,
+                                        &PySet_Type,
+                                        &pyopts,
+                                        &PySet_Type,
+                                        &pyopts_override,
+                                        &PySet_Type,
+                                        &py_tags,
+                                        &pysubtype,
+                                        &update_fn,
+                                        &get_fn,
+                                        &set_fn)) {
+    return NULL;
+  }
 
-    BPY_PROPDEF_SUBTYPE_CHECK(BoolProperty,
-                              property_flag_items,
-                              property_flag_override_items,
-                              property_subtype_number_items);
+  BPY_PROPDEF_SUBTYPE_CHECK(BoolProperty,
+                            property_flag_items,
+                            property_flag_override_items,
+                            property_subtype_number_items);
 
-    if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
-      return NULL;
-    }
-    if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
-      return NULL;
-    }
-    if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
-      return NULL;
-    }
+  if (bpy_prop_callback_check(update_fn, "update", 2) == -1) {
+    return NULL;
+  }
+  if (bpy_prop_callback_check(get_fn, "get", 1) == -1) {
+    return NULL;
+  }
+  if (bpy_prop_callback_check(set_fn, "set", 2) == -1) {
+    return NULL;
+  }
 
-    prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
-    RNA_def_property_boolean_default(prop, def);
-    RNA_def_property_ui_text(prop, name ? name : id, description);
+  prop = RNA_def_property(srna, id, PROP_BOOLEAN, subtype);
+  RNA_def_property_boolean_default(prop, def);
+  RNA_def_property_ui_text(prop, name ? name : id, description);
 
-    if (py_tags) {
-      RNA_def_property_tags(prop, prop_tags);
-    }
-    if (pyopts) {
-      bpy_prop_assign_flag(prop, opts);
-    }
-    if (pyopts_override) {
-      bpy_prop_assign_flag_override(prop, opts_override);
-    }
-    bpy_prop_callback_assign_update(prop, update_fn);
-    bpy_prop_callback_assign_boolean(prop, get_fn, set_fn);
-    RNA_def_property_duplicate_pointers(srna, prop);
+  if (py_tags) {
+    RNA_def_property_tags(prop, prop_tags);
+  }
+  if (pyopts) {
+    bpy_prop_assign_flag(prop, opts);
+  }
+  if (pyopts_override) {
+    bpy_prop_assign_flag_override(prop, opts_override);
   }
+  bpy_prop_callback_assign_update(prop, update_fn);
+  bpy_prop_callback_assign_boolean(prop, get_fn, set_fn);
+  RNA_def_property_duplicate_pointers(srna, prop);
 
   Py_RETURN_NONE;
 }
@@ -2546,123 +2551,122 @@ PyDoc_STRVAR(
             BPY_PROPDEF_UPDATE_DOC BPY_PROPDEF_GET_DOC BPY_PROPDEF_SET_DOC);
 static PyObject *BPy_BoolVectorProperty(PyObject *self, PyObject *args, 
PyObject *kw)
 {
+  /* Keep this block first. */
   StructRNA *srna;
-
   BPY_PROPDEF_HEAD(BoolVectorProperty);
+  BLI_assert(srna != NULL);
+
+  const char *id = NULL, *name = NULL, *description = "";
+  Py_ssize_t id_len;
+  bool def[PYRNA_STACK_ARRAY] = {0};
+  int size = 3;
+  PropertyRNA *prop;
+  PyObject *pydef = NULL;
+  PyObject *pyopts = NULL;
+  PyObject *pyopts_override = NULL;
+  int opts = 0;
+  int opts_override = 0;
+  int prop_tags = 0;
+  const char *pysubtype = NULL;
+  int subtype = PROP_NONE;
+  PyObject *update_fn = NULL;
+  PyObject *get_fn = NULL;
+  PyObject *set_fn = NULL;
+  PyObject *py_tags = NULL;
 
-  if (srna) {
-    const char *id = NULL, *name = NULL, *description = "";
-    Py_ssize_t id_len;
-    bool def[PYRNA_STACK_ARRAY] = {0};
-    int size = 3;
-    PropertyRNA *prop;
-    PyObject *pydef = NULL;
-    PyObject *pyopts = NULL;
-    PyObject *pyopts_override = NULL;
-    int opts = 0;
-    int opts_override = 0;
-    int prop_tags = 0;
-    const char *pysubtype = NULL;
-    int subtype = PROP_NONE;
-    PyObject *update_fn = NULL;
-    PyObject *get_fn = NULL;
-    PyObject *set_fn = NULL;
-    PyObject *py_tags = NULL;
-
-    static const char *_keywords[] = {
-        "attr",
-        "name",
-        "description",
-        "default",
-        "options",
-        "override",
-        "tags",
-        "subtype",
-        "size",
-        "update",
-        "get",
-        "set",
-        NULL,
-    };
-    static _PyArg_Parser _parser = {"s#|$ssOO!O!O!siOOO:BoolVectorProperty", 
_keywords, 0};
-    if (!_PyArg_ParseTupleAndKeywordsFast(args,
-                                          kw,
-                                          &_parser,
-                                          &id,
-                                          &id_len,
-                                          &name,
-                                          &description,
-                                          &pydef,
-                                          &PySet_Ty

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to