diff options
Diffstat (limited to 'source/blender/python/intern/bpy_rna.c')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 72553872057..4abcbc684e2 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -1117,6 +1117,7 @@ static int pyrna_string_to_enum(PyObject *item, PointerRNA *ptr, PropertyRNA *pr return 1; } +/* 'value' _must_ be a set type, error check before calling */ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_value, const char *error_prefix) { /* set of enum items, concatenate all values with OR */ @@ -1138,8 +1139,10 @@ int pyrna_set_to_enum_bitfield(EnumPropertyItem *items, PyObject *value, int *r_ error_prefix, Py_TYPE(key)->tp_name); return -1; } - if(pyrna_enum_value_from_id(items, param, &ret, error_prefix) < 0) + + if(pyrna_enum_value_from_id(items, param, &ret, error_prefix) < 0) { return -1; + } flag |= ret; } @@ -1156,6 +1159,14 @@ static int pyrna_prop_to_enum_bitfield(PointerRNA *ptr, PropertyRNA *prop, PyObj *r_value= 0; + if (!PyAnySet_Check(value)) { + PyErr_Format(PyExc_TypeError, + "%.200s, %.200s.%.200s expected a set, not a %.200s", + error_prefix, RNA_struct_identifier(ptr->type), + RNA_property_identifier(prop), Py_TYPE(value)->tp_name); + return -1; + } + RNA_property_enum_items(BPy_GetContext(), ptr, prop, &item, NULL, &free); if(item) { @@ -1529,33 +1540,18 @@ static int pyrna_py_to_prop(PointerRNA *ptr, PropertyRNA *prop, void *data, PyOb { int val= 0; - if (PyUnicode_Check(value)) { - if (!pyrna_string_to_enum(value, ptr, prop, &val, error_prefix)) - return -1; - } - else if (PyAnySet_Check(value)) { - if(RNA_property_flag(prop) & PROP_ENUM_FLAG) { - /* set of enum items, concatenate all values with OR */ - if(pyrna_prop_to_enum_bitfield(ptr, prop, value, &val, error_prefix) < 0) - return -1; - } - else { - PyErr_Format(PyExc_TypeError, - "%.200s, %.200s.%.200s is not a bitflag enum type", - error_prefix, RNA_struct_identifier(ptr->type), - RNA_property_identifier(prop)); + /* type checkins is done by each function */ + if(RNA_property_flag(prop) & PROP_ENUM_FLAG) { + /* set of enum items, concatenate all values with OR */ + if(pyrna_prop_to_enum_bitfield(ptr, prop, value, &val, error_prefix) < 0) { return -1; } } else { - const char *enum_str= pyrna_enum_as_string(ptr, prop); - PyErr_Format(PyExc_TypeError, - "%.200s %.200s.%.200s expected a string enum or a set of strings in (%.2000s), not %.200s", - error_prefix, RNA_struct_identifier(ptr->type), - RNA_property_identifier(prop), enum_str, - Py_TYPE(value)->tp_name); - MEM_freeN((void *)enum_str); - return -1; + /* simple enum string */ + if (!pyrna_string_to_enum(value, ptr, prop, &val, error_prefix) < 0) { + return -1; + } } if(data) *((int*)data)= val; @@ -4320,7 +4316,6 @@ static PyObject *small_dict_get_item_string(PyObject *dict, const char *key_look Py_ssize_t pos = 0; PyObject *value = NULL; - /* case not, search for it in the script's global dictionary */ while (PyDict_Next(dict, &pos, &key, &value)) { if(PyUnicode_Check(key)) { if(strcmp(key_lookup, _PyUnicode_AsString(key))==0) { @@ -6422,7 +6417,21 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param err= -1; } else if(ret_len==1) { - err= pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, "calling class function:"); + err= pyrna_py_to_prop(&funcptr, pret_single, retdata_single, ret, ""); + + /* when calling operator funcs only gives Function.result with + * no line number since the func has finished calling on error, + * re-raise the exception with more info since it would be slow to + * create prefix on every call (when there are no errors) */ + if(err == -1 && PyErr_Occurred()) { + PyObject *error_type, *error_value, *error_traceback; + PyErr_Fetch(&error_type, &error_value, &error_traceback); + + PyErr_Format(error_type, + "class %.200s, function %.200s: incompatible return value%S", + RNA_struct_identifier(ptr->type), RNA_function_identifier(func), + error_value); + } } else if (ret_len > 1) { @@ -6582,9 +6591,9 @@ void pyrna_free_types(void) PyDoc_STRVAR(pyrna_register_class_doc, ".. method:: register_class(cls)\n" "\n" -" Register a subclass of a blender type in (:class:`Panel`,\n" -" :class:`Menu`, :class:`Header`, :class:`Operator`,\n" -" :class:`KeyingSetInfo`, :class:`RenderEngine`).\n" +" Register a subclass of a blender type in (:class:`bpy.types.Panel`,\n" +" :class:`bpy.types.Menu`, :class:`bpy.types.Header`, :class:`bpy.types.Operator`,\n" +" :class:`bpy.types.KeyingSetInfo`, :class:`bpy.types.RenderEngine`).\n" "\n" " If the class has a *register* class method it will be called\n" " before registration.\n" |