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.
This commit is contained in:
parent
12f60e7825
commit
fff8a519b8
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue