Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2018-07-11 23:18:09 +0300
committerCampbell Barton <ideasman42@gmail.com>2018-07-11 23:18:09 +0300
commit09aa799e5331a9da666f8a6325b038a866b1f35d (patch)
treeccff0086f70ea7929554a7e4c90bd1182f125ba6 /source
parente3c85aaca74fc7bd2a9da43a0396a886363bc93d (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')
-rw-r--r--source/blender/python/intern/bpy_intern_string.c4
-rw-r--r--source/blender/python/intern/bpy_intern_string.h2
-rw-r--r--source/blender/python/intern/bpy_rna.c33
3 files changed, 24 insertions, 15 deletions
diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c
index 6911e985e93..41276963fc9 100644
--- a/source/blender/python/intern/bpy_intern_string.c
+++ b/source/blender/python/intern/bpy_intern_string.c
@@ -36,6 +36,7 @@
static PyObject *bpy_intern_str_arr[16];
+PyObject *bpy_intern_str___annotations__;
PyObject *bpy_intern_str___doc__;
PyObject *bpy_intern_str___main__;
PyObject *bpy_intern_str___module__;
@@ -47,7 +48,6 @@ PyObject *bpy_intern_str_bl_rna;
PyObject *bpy_intern_str_bl_target_properties;
PyObject *bpy_intern_str_bpy_types;
PyObject *bpy_intern_str_frame;
-PyObject *bpy_intern_str_order;
PyObject *bpy_intern_str_properties;
PyObject *bpy_intern_str_register;
PyObject *bpy_intern_str_self;
@@ -60,6 +60,7 @@ void bpy_intern_string_init(void)
#define BPY_INTERN_STR(var, str) \
{ var = bpy_intern_str_arr[i++] = PyUnicode_FromString(str); } (void)0
+ BPY_INTERN_STR(bpy_intern_str___annotations__, "__annotations__");
BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__");
BPY_INTERN_STR(bpy_intern_str___main__, "__main__");
BPY_INTERN_STR(bpy_intern_str___module__, "__module__");
@@ -71,7 +72,6 @@ void bpy_intern_string_init(void)
BPY_INTERN_STR(bpy_intern_str_bl_target_properties, "bl_target_properties");
BPY_INTERN_STR(bpy_intern_str_bpy_types, "bpy.types");
BPY_INTERN_STR(bpy_intern_str_frame, "frame");
- BPY_INTERN_STR(bpy_intern_str_order, "order");
BPY_INTERN_STR(bpy_intern_str_properties, "properties");
BPY_INTERN_STR(bpy_intern_str_register, "register");
BPY_INTERN_STR(bpy_intern_str_self, "self");
diff --git a/source/blender/python/intern/bpy_intern_string.h b/source/blender/python/intern/bpy_intern_string.h
index 998c312c321..41cd58f9c3d 100644
--- a/source/blender/python/intern/bpy_intern_string.h
+++ b/source/blender/python/intern/bpy_intern_string.h
@@ -30,6 +30,7 @@
void bpy_intern_string_init(void);
void bpy_intern_string_exit(void);
+extern PyObject *bpy_intern_str___annotations__;
extern PyObject *bpy_intern_str___doc__;
extern PyObject *bpy_intern_str___main__;
extern PyObject *bpy_intern_str___module__;
@@ -41,7 +42,6 @@ extern PyObject *bpy_intern_str_bl_rna;
extern PyObject *bpy_intern_str_bl_target_properties;
extern PyObject *bpy_intern_str_bpy_types;
extern PyObject *bpy_intern_str_frame;
-extern PyObject *bpy_intern_str_order;
extern PyObject *bpy_intern_str_properties;
extern PyObject *bpy_intern_str_register;
extern PyObject *bpy_intern_str_self;
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)