summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-16 18:52:43 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-16 18:52:43 (GMT)
commit76e6963fc122fd3ed17794b4f7db6b1f20efeeab (patch)
tree4749d57fee21df52c16d0a929ef1014e8db98bd1
parent3791838339f8c75cdce0bf9615817b1263234314 (diff)
downloadcpython-76e6963fc122fd3ed17794b4f7db6b1f20efeeab.zip
cpython-76e6963fc122fd3ed17794b4f7db6b1f20efeeab.tar.gz
cpython-76e6963fc122fd3ed17794b4f7db6b1f20efeeab.tar.bz2
Fix object_repr() to include the module (using the same rules as
type_repr() for when to show or not to show it).
-rw-r--r--Objects/typeobject.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index f7f2c97..c38340e 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -912,9 +912,30 @@ object_dealloc(PyObject *self)
static PyObject *
object_repr(PyObject *self)
{
- char buf[120];
+ PyTypeObject *type;
+ PyObject *mod, *name;
+ char buf[200];
- sprintf(buf, "<%.80s object at %p>", self->ob_type->tp_name, self);
+ type = self->ob_type;
+ mod = type_module(type, NULL);
+ if (mod == NULL)
+ PyErr_Clear();
+ else if (!PyString_Check(mod)) {
+ Py_DECREF(mod);
+ mod = NULL;
+ }
+ name = type_name(type, NULL);
+ if (name == NULL)
+ return NULL;
+ if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__"))
+ sprintf(buf, "<%.80s.%.80s instance at %p>",
+ PyString_AS_STRING(mod),
+ PyString_AS_STRING(name),
+ self);
+ else
+ sprintf(buf, "<%.80s instance at %p>", type->tp_name, self);
+ Py_XDECREF(mod);
+ Py_DECREF(name);
return PyString_FromString(buf);
}