[pypy-commit] pypy default: fix attribute error message for heap types

bdkearns noreply at buildbot.pypy.org
Fri May 2 01:48:20 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: 
Changeset: r71162:02389a744344
Date: 2014-05-01 19:44 -0400
http://bitbucket.org/pypy/pypy/changeset/02389a744344/

Log:	fix attribute error message for heap types

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
@@ -70,6 +70,13 @@
         raises(AttributeError, getattr, type, "__abstractmethods__")
         raises(TypeError, "int.__abstractmethods__ = ('abc', )")
 
+    def test_attribute_error(self):
+        class X(object):
+            __module__ = 'test'
+        x = X()
+        exc = raises(AttributeError, "x.a")
+        assert str(exc.value) == "'X' object has no attribute 'a'"
+
     def test_call_type(self):
         assert type(42) is int
         C = type('C', (object,), {'x': lambda: 42})
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
@@ -489,11 +489,12 @@
 
     def get_module_type_name(w_self):
         space = w_self.space
-        w_mod = w_self.get_module()
-        if space.isinstance_w(w_mod, space.w_str):
-            mod = space.str_w(w_mod)
-            if mod != '__builtin__':
-                return '%s.%s' % (mod, w_self.name)
+        if not w_self.is_heaptype():
+            w_mod = w_self.get_module()
+            if space.isinstance_w(w_mod, space.w_str):
+                mod = space.str_w(w_mod)
+                if mod != '__builtin__':
+                    return '%s.%s' % (mod, w_self.name)
         return w_self.name
 
     def getname(w_self, space):


More information about the pypy-commit mailing list