Skip to content

Commit

Permalink
Fix object_repr() to include the module (using the same rules as
Browse files Browse the repository at this point in the history
type_repr() for when to show or not to show it).
  • Loading branch information
gvanrossum committed Aug 16, 2001
1 parent 3791838 commit 76e6963
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 76e6963

Please sign in to comment.