[Bf-blender-cvs] [fff8a51] master: Py Enum props definition: 'default' parameter cleanup/fix.

Bastien Montagne noreply at git.blender.org
Fri Feb 27 23:07:41 CET 2015


Commit: fff8a519b85da12fd9582bc1e83d5e63faeaedea
Author: Bastien Montagne
Date:   Fri Feb 27 23:02:13 2015 +0100
Branches: master
https://developer.blender.org/rBfff8a519b85da12fd9582bc1e83d5e63faeaedea

Py Enum props definition: 'default' parameter cleanup/fix.

* There was no real default value for this parameter (neither "" nor None would work the same as
  not specifying that parameter). Now, 'None' is considered as default value, and you get
  exact same behavior with this value and if not specifying it. This is important at least for
  consistency, and potentially too in some esoteric cases (like generated code or so).
* Add a warning about the fact that 'default' parameter shall not be psecified when items
  are given a callback function.

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

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 b536e91..8370aea 100644
--- a/source/blender/python/intern/bpy_props.c
+++ b/source/blender/python/intern/bpy_props.c
@@ -2600,7 +2600,7 @@ PyDoc_STRVAR(BPy_EnumProperty_doc,
 ".. function:: EnumProperty(items, "
                            "name=\"\", "
                            "description=\"\", "
-                           "default=\"\", "
+                           "default=None, "
                            "options={'ANIMATABLE'}, "
                            "update=None, "
                            "get=None, "
@@ -2625,6 +2625,8 @@ BPY_PROPDEF_NAME_DOC
 BPY_PROPDEF_DESC_DOC
 "   :arg default: The default value for this enum, a string from the identifiers used in *items*.\n"
 "      If the *ENUM_FLAG* option is used this must be a set of such string identifiers instead.\n"
+"      WARNING: It shall not be specified (or specified to its default *None* value) for dynamic enums\n"
+"      (i.e. if a callback function is given as *items* parameter).\n"
 "   :type default: string or set\n"
 BPY_PROPDEF_OPTIONS_ENUM_DOC
 BPY_PROPDEF_UPDATE_DOC
@@ -2676,6 +2678,12 @@ static PyObject *BPy_EnumProperty(PyObject *self, PyObject *args, PyObject *kw)
 			return NULL;
 		}
 
+		if (def == Py_None) {
+			/* This allows to get same behavior when explicitely passing None as default value,
+			 * and not defining a default value at all! */
+			def = NULL;
+		}
+
 		/* items can be a list or a callable */
 		if (PyFunction_Check(items)) { /* don't use PyCallable_Check because we need the function code for errors */
 			PyCodeObject *f_code = (PyCodeObject *)PyFunction_GET_CODE(items);




More information about the Bf-blender-cvs mailing list