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.
This commit is contained in:
@@ -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");
|
||||
|
@@ -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;
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user