[pypy-commit] pypy py3k: update type's repr

pjenvey noreply at buildbot.pypy.org
Thu Nov 10 20:43:06 CET 2011


Author: Philip Jenvey <pjenvey at underboss.org>
Branch: py3k
Changeset: r49288:21b2914fdb96
Date: 2011-11-10 11:42 -0800
http://bitbucket.org/pypy/pypy/changeset/21b2914fdb96/

Log:	update type's repr

diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -739,10 +739,10 @@
         class A(object):
             pass
         assert repr(A) == "<class 'a.A'>"
-        assert repr(type(type)) == "<type 'type'>" 
-        assert repr(complex) == "<type 'complex'>"
-        assert repr(property) == "<type 'property'>"
-        assert repr(TypeError) == "<type 'exceptions.TypeError'>"
+        assert repr(type(type)) == "<class 'type'>"
+        assert repr(complex) == "<class 'complex'>"
+        assert repr(property) == "<class 'property'>"
+        assert repr(TypeError) == "<class 'TypeError'>"
         
     def test_invalid_mro(self):
         class A(object):
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -518,10 +518,10 @@
     def get_module_type_name(w_self):
         space = w_self.space
         w_mod = w_self.get_module()
-        if not space.isinstance_w(w_mod, space.w_str):
+        if not space.isinstance_w(w_mod, space.w_unicode):
             mod = 'builtins'
         else:
-            mod = space.str_w(w_mod)
+            mod = space.unicode_w(w_mod)
         if mod != 'builtins':
             return '%s.%s' % (mod, w_self.name)
         else:
@@ -871,19 +871,14 @@
 
 def repr__Type(space, w_obj):
     w_mod = w_obj.get_module()
-    if not space.isinstance_w(w_mod, space.w_str):
+    if not space.isinstance_w(w_mod, space.w_unicode):
         mod = None
     else:
-        mod = space.str_w(w_mod)
-    if (not w_obj.is_heaptype() or
-        (mod == '__builtin__' or mod == 'exceptions')):
-        kind = 'type'
+        mod = space.unicode_w(w_mod)
+    if mod is not None and mod != 'builtins':
+        return space.wrap("<class '%s.%s'>" % (mod, w_obj.name))
     else:
-        kind = 'class'
-    if mod is not None and mod !='builtins':
-        return space.wrap("<%s '%s.%s'>" % (kind, mod, w_obj.name))
-    else:
-        return space.wrap("<%s '%s'>" % (kind, w_obj.name))
+        return space.wrap("<class '%s'>" % (w_obj.name))
 
 def getattr__Type_ANY(space, w_type, w_name):
     name = space.str_w(w_name)


More information about the pypy-commit mailing list