summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-12-03 00:06:02 (GMT)
committerGuido van Rossum <guido@python.org>1997-12-03 00:06:02 (GMT)
commitb7f1afe4a84c6ca6ecb3005e1ba3ef801a0257e7 (patch)
treef37af6a0a6075ca342f1e0aac9f3e6218dbe0b5d /Objects
parent5c38bf6c62eb9590fb0616120e51aeac220bfc0a (diff)
downloadcpython-b7f1afe4a84c6ca6ecb3005e1ba3ef801a0257e7.zip
cpython-b7f1afe4a84c6ca6ecb3005e1ba3ef801a0257e7.tar.gz
cpython-b7f1afe4a84c6ca6ecb3005e1ba3ef801a0257e7.tar.bz2
Change the default repr() and str() of class instance objects to look
like <modulename.classname instance at ...> (to match the repr() of class objects.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/classobject.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index b67265b..b6052a0 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -655,13 +655,21 @@ instance_repr(inst)
if (func == NULL) {
char buf[140];
PyObject *classname = inst->in_class->cl_name;
+ PyObject *mod = PyDict_GetItemString(
+ inst->in_class->cl_dict, "__module__");
char *cname;
if (classname != NULL && PyString_Check(classname))
cname = PyString_AsString(classname);
else
cname = "?";
PyErr_Clear();
- sprintf(buf, "<%.100s instance at %lx>", cname, (long)inst);
+ if (mod == NULL || !PyString_Check(mod))
+ sprintf(buf, "<?.%.100s instance at %lx>",
+ cname, (long)inst);
+ else
+ sprintf(buf, "<%.50s.%.50s instance at %lx>",
+ PyString_AsString(mod),
+ cname, (long)inst);
return PyString_FromString(buf);
}
res = PyEval_CallObject(func, (PyObject *)NULL);