[Bf-blender-cvs] [952212ac69a] master: Fix printing data from an evaluated depsgraph in Python
Campbell Barton
noreply at git.blender.org
Sun Sep 13 07:50:50 CEST 2020
Commit: 952212ac69a5d1d16f9fac7ab19456c256382d97
Author: Campbell Barton
Date: Sun Sep 13 15:37:01 2020 +1000
Branches: master
https://developer.blender.org/rB952212ac69a5d1d16f9fac7ab19456c256382d97
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).
===================================================================
M source/blender/python/intern/bpy_rna.c
===================================================================
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);
}
More information about the Bf-blender-cvs
mailing list