diff --git a/Lib/test/test_descrtut.py b/Lib/test/test_descrtut.py index e72567dabe6..a0de4cccb63 100644 --- a/Lib/test/test_descrtut.py +++ b/Lib/test/test_descrtut.py @@ -37,16 +37,16 @@ test_1 = """ Here's the new type at work: >>> print defaultdict # show our type - + >>> print type(defaultdict) # its metatype >>> a = defaultdict(default=0.0) # create an instance >>> print a # show the instance {} >>> print type(a) # show its type - + >>> print a.__class__ # show its class - + >>> print type(a) is a.__class__ # its type is its class 1 >>> a[1] = 3.25 # modify the instance diff --git a/Lib/test/test_repr.py b/Lib/test/test_repr.py index b7d937481dd..1c63e4dc2ce 100644 --- a/Lib/test/test_repr.py +++ b/Lib/test/test_repr.py @@ -208,7 +208,7 @@ class foo(object): ''') from areallylongpackageandmodulenametotestreprtruncation.areallylongpackageandmodulenametotestreprtruncation import foo eq(repr(foo.foo), - "") + "") def test_object(self): # XXX Test the repr of a type with a really long tp_name but with no diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 877a3bd8705..964164fd271 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("", + rtn = PyString_FromFormat("<%s '%s.%s'>", + kind, PyString_AS_STRING(mod), PyString_AS_STRING(name)); } else - rtn = PyString_FromFormat("", 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( - ", <%s object>>", + ", <%s object>>", su->type ? su->type->tp_name : "NULL", su->obj->ob_type->tp_name); else return PyString_FromFormat( - ", NULL>", + ", NULL>", su->type ? su->type->tp_name : "NULL"); }