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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2020-09-13 08:37:01 +0300
committerCampbell Barton <ideasman42@gmail.com>2020-09-13 08:49:55 +0300
commit952212ac69a5d1d16f9fac7ab19456c256382d97 (patch)
treeb45357dceb6c2f49fabc29cd9605cc81b876dec6
parentca393258262625a82a3389bf3ad6a8dc6cd22dff (diff)
Fix printing data from an evaluated depsgraph in Python
Printing an evaluated view layer would show: Evaluated Scene 'Scene' - Now __repr__ uses the __str__ fallback for evaluated data, as done in other situations where we can't create a string that would evaluate to the data. - __str__ now shows when the data is evaluated. - __str__ always includes the memory address (which was previously only shown for structs without a name).
-rw-r--r--source/blender/python/intern/bpy_rna.c32
1 files changed, 21 insertions, 11 deletions
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 0980d9df762..2a773519cb6 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -890,22 +890,36 @@ static PyObject *pyrna_struct_str(BPy_StructRNA *self)
{
PyObject *ret;
const char *name;
+ const char *extra_info = "";
if (!PYRNA_STRUCT_IS_VALID(self)) {
return PyUnicode_FromFormat("<bpy_struct, %.200s invalid>", Py_TYPE(self)->tp_name);
}
- /* Print name if available. */
+ ID *id = self->ptr.owner_id;
+ if (id && id != DEG_get_original_id(id)) {
+ extra_info = ", evaluated";
+ }
+
+ /* Print name if available.
+ *
+ * Always include the pointer address since it can help identify unique data,
+ * or when data is re-allocated internally. */
name = RNA_struct_name_get_alloc(&self->ptr, NULL, 0, NULL);
if (name) {
- ret = PyUnicode_FromFormat(
- "<bpy_struct, %.200s(\"%.200s\")>", RNA_struct_identifier(self->ptr.type), name);
+ ret = PyUnicode_FromFormat("<bpy_struct, %.200s(\"%.200s\") at %p%s>",
+ RNA_struct_identifier(self->ptr.type),
+ name,
+ self->ptr.data,
+ extra_info);
MEM_freeN((void *)name);
return ret;
}
- return PyUnicode_FromFormat(
- "<bpy_struct, %.200s at %p>", RNA_struct_identifier(self->ptr.type), self->ptr.data);
+ return PyUnicode_FromFormat("<bpy_struct, %.200s at %p%s>",
+ RNA_struct_identifier(self->ptr.type),
+ self->ptr.data,
+ extra_info);
}
static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
@@ -914,18 +928,14 @@ static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
PyObject *tmp_str;
PyObject *ret;
- if (id == NULL || !PYRNA_STRUCT_IS_VALID(self)) {
+ if (id == NULL || !PYRNA_STRUCT_IS_VALID(self) || (DEG_get_original_id(id) != id)) {
/* fallback */
return pyrna_struct_str(self);
}
tmp_str = PyUnicode_FromString(id->name + 2);
- if (DEG_get_original_id(id) != id) {
- ret = PyUnicode_FromFormat(
- "Evaluated %s %R", BKE_idtype_idcode_to_name(GS(id->name)), tmp_str);
- }
- else if (RNA_struct_is_ID(self->ptr.type) && (id->flag & LIB_EMBEDDED_DATA) == 0) {
+ if (RNA_struct_is_ID(self->ptr.type) && (id->flag & LIB_EMBEDDED_DATA) == 0) {
ret = PyUnicode_FromFormat(
"bpy.data.%s[%R]", BKE_idtype_idcode_to_name_plural(GS(id->name)), tmp_str);
}