summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-25 03:56:29 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-25 03:56:29 (GMT)
commita4cb78874ce31bef1a4c05bd5bace387bc5bb677 (patch)
tree693cfdc4e8d4fc477c10a6a9dd59cbe216b99e62 /Objects
parent5c294fb0e634afc4807ca83032ace356512c97dc (diff)
downloadcpython-a4cb78874ce31bef1a4c05bd5bace387bc5bb677.zip
cpython-a4cb78874ce31bef1a4c05bd5bace387bc5bb677.tar.gz
cpython-a4cb78874ce31bef1a4c05bd5bace387bc5bb677.tar.bz2
Change repr() of a new-style class to say <class 'ClassName'> rather
than <type 'ClassName'>. Exception: if it's a built-in type or an extension type, continue to call it <type 'ClassName>. Call me a wimp, but I don't want to break more user code than necessary.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/typeobject.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 877a3bd..964164f 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -114,6 +114,7 @@ static PyObject *
type_repr(PyTypeObject *type)
{
PyObject *mod, *name, *rtn;
+ char *kind;
mod = type_module(type, NULL);
if (mod == NULL)
@@ -126,13 +127,19 @@ type_repr(PyTypeObject *type)
if (name == NULL)
return NULL;
+ if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
+ kind = "class";
+ else
+ kind = "type";
+
if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) {
- rtn = PyString_FromFormat("<type '%s.%s'>",
+ rtn = PyString_FromFormat("<%s '%s.%s'>",
+ kind,
PyString_AS_STRING(mod),
PyString_AS_STRING(name));
}
else
- rtn = PyString_FromFormat("<type '%s'>", type->tp_name);
+ rtn = PyString_FromFormat("<%s '%s'>", kind, type->tp_name);
Py_XDECREF(mod);
Py_DECREF(name);
@@ -3365,12 +3372,12 @@ super_repr(PyObject *self)
if (su->obj)
return PyString_FromFormat(
- "<super: <type '%s'>, <%s object>>",
+ "<super: <class '%s'>, <%s object>>",
su->type ? su->type->tp_name : "NULL",
su->obj->ob_type->tp_name);
else
return PyString_FromFormat(
- "<super: <type '%s'>, NULL>",
+ "<super: <class '%s'>, NULL>",
su->type ? su->type->tp_name : "NULL");
}