diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-07-11 23:18:09 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-07-11 23:18:09 +0300 |
commit | 09aa799e5331a9da666f8a6325b038a866b1f35d (patch) | |
tree | ccff0086f70ea7929554a7e4c90bd1182f125ba6 /source/blender/python/intern/bpy_rna.c | |
parent | e3c85aaca74fc7bd2a9da43a0396a886363bc93d (diff) |
PyAPI: Use annotations for RNA definitions
- Logical use of fields since they define type information.
- Avoids using ordered-dict metaclass.
Properties using regular assignments will print a warning and load,
however the order is undefined.
Diffstat (limited to 'source/blender/python/intern/bpy_rna.c')
-rw-r--r-- | source/blender/python/intern/bpy_rna.c | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 3e1c85d7f9f..00ff63f7275 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -7423,29 +7423,38 @@ static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject *item static int pyrna_deferred_register_props(StructRNA *srna, PyObject *class_dict) { + PyObject *fields_dict; PyObject *item, *key; - PyObject *order; Py_ssize_t pos = 0; int ret = 0; /* in both cases PyDict_CheckExact(class_dict) will be true even * though Operators have a metaclass dict namespace */ + if ((fields_dict = PyDict_GetItem(class_dict, bpy_intern_str___annotations__)) && PyDict_CheckExact(fields_dict)) { + while (PyDict_Next(fields_dict, &pos, &key, &item)) { + ret = deferred_register_prop(srna, key, item); - if ((order = PyDict_GetItem(class_dict, bpy_intern_str_order)) && PyList_CheckExact(order)) { - for (pos = 0; pos < PyList_GET_SIZE(order); pos++) { - key = PyList_GET_ITEM(order, pos); - /* however unlikely its possible - * fails in py 3.3 beta with __qualname__ */ - if ((item = PyDict_GetItem(class_dict, key))) { - ret = deferred_register_prop(srna, key, item); - if (ret != 0) { - break; - } + if (ret != 0) { + break; } } } - else { + + { + /* This block can be removed once 2.8x is released and fields are in use. */ + bool has_warning = false; while (PyDict_Next(class_dict, &pos, &key, &item)) { + if (pyrna_is_deferred_prop(item)) { + if (!has_warning) { + PyC_StackSpit(); + printf("Warning: class %.200s " + "contains a properties which should be a field!\n", + RNA_struct_identifier(srna)); + has_warning = true; + } + printf(" make field: %.200s.%.200s\n", + RNA_struct_identifier(srna), _PyUnicode_AsString(key)); + } ret = deferred_register_prop(srna, key, item); if (ret != 0) |