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).
This commit is contained in:
@@ -890,22 +890,36 @@ static PyObject *pyrna_struct_str(BPy_StructRNA *self)
|
|||||||
{
|
{
|
||||||
PyObject *ret;
|
PyObject *ret;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char *extra_info = "";
|
||||||
|
|
||||||
if (!PYRNA_STRUCT_IS_VALID(self)) {
|
if (!PYRNA_STRUCT_IS_VALID(self)) {
|
||||||
return PyUnicode_FromFormat("<bpy_struct, %.200s invalid>", Py_TYPE(self)->tp_name);
|
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);
|
name = RNA_struct_name_get_alloc(&self->ptr, NULL, 0, NULL);
|
||||||
if (name) {
|
if (name) {
|
||||||
ret = PyUnicode_FromFormat(
|
ret = PyUnicode_FromFormat("<bpy_struct, %.200s(\"%.200s\") at %p%s>",
|
||||||
"<bpy_struct, %.200s(\"%.200s\")>", RNA_struct_identifier(self->ptr.type), name);
|
RNA_struct_identifier(self->ptr.type),
|
||||||
|
name,
|
||||||
|
self->ptr.data,
|
||||||
|
extra_info);
|
||||||
MEM_freeN((void *)name);
|
MEM_freeN((void *)name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return PyUnicode_FromFormat(
|
return PyUnicode_FromFormat("<bpy_struct, %.200s at %p%s>",
|
||||||
"<bpy_struct, %.200s at %p>", RNA_struct_identifier(self->ptr.type), self->ptr.data);
|
RNA_struct_identifier(self->ptr.type),
|
||||||
|
self->ptr.data,
|
||||||
|
extra_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
|
static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
|
||||||
@@ -914,18 +928,14 @@ static PyObject *pyrna_struct_repr(BPy_StructRNA *self)
|
|||||||
PyObject *tmp_str;
|
PyObject *tmp_str;
|
||||||
PyObject *ret;
|
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 */
|
/* fallback */
|
||||||
return pyrna_struct_str(self);
|
return pyrna_struct_str(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp_str = PyUnicode_FromString(id->name + 2);
|
tmp_str = PyUnicode_FromString(id->name + 2);
|
||||||
|
|
||||||
if (DEG_get_original_id(id) != id) {
|
if (RNA_struct_is_ID(self->ptr.type) && (id->flag & LIB_EMBEDDED_DATA) == 0) {
|
||||||
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) {
|
|
||||||
ret = PyUnicode_FromFormat(
|
ret = PyUnicode_FromFormat(
|
||||||
"bpy.data.%s[%R]", BKE_idtype_idcode_to_name_plural(GS(id->name)), tmp_str);
|
"bpy.data.%s[%R]", BKE_idtype_idcode_to_name_plural(GS(id->name)), tmp_str);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user