[pypy-svn] r39868 - in pypy/dist/pypy: rpython/ootypesystem tool tool/test

fijal at codespeak.net fijal at codespeak.net
Sun Mar 4 12:40:19 CET 2007


Author: fijal
Date: Sun Mar  4 12:40:18 2007
New Revision: 39868

Modified:
   pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
   pypy/dist/pypy/tool/error.py
   pypy/dist/pypy/tool/test/test_error.py
Log:
Improve error reporting of BasicExternal


Modified: pypy/dist/pypy/rpython/ootypesystem/bltregistry.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/bltregistry.py	Sun Mar  4 12:40:18 2007
@@ -166,7 +166,12 @@
     
     def get_field(self, attr):
         self.check_update()
-        return self._fields[attr]
+        try:
+            return self._fields[attr]
+        except KeyError:
+            from pypy.tool.error import NoSuchAttrError
+            raise NoSuchAttrError("Basic external %s has no attribute %s" %
+                                  (self._class_, attr))
 
     def find_method(self, meth):
         raise NotImplementedError()

Modified: pypy/dist/pypy/tool/error.py
==============================================================================
--- pypy/dist/pypy/tool/error.py	(original)
+++ pypy/dist/pypy/tool/error.py	Sun Mar  4 12:40:18 2007
@@ -67,6 +67,9 @@
 class AnnotatorError(Exception):
     pass
 
+class NoSuchAttrError(Exception):
+    pass
+
 def gather_error(annotator, block, graph):
     msg = [""]
     msg.append('-+' * 30)

Modified: pypy/dist/pypy/tool/test/test_error.py
==============================================================================
--- pypy/dist/pypy/tool/test/test_error.py	(original)
+++ pypy/dist/pypy/tool/test/test_error.py	Sun Mar  4 12:40:18 2007
@@ -3,7 +3,7 @@
 """
 
 from pypy.translator.translator import TranslationContext
-from pypy.tool.error import FlowingError, AnnotatorError
+from pypy.tool.error import FlowingError, AnnotatorError, NoSuchAttrError
 from pypy.annotation.policy import BasicAnnotatorPolicy
 
 import py
@@ -68,3 +68,19 @@
     exec("def f(n):\n if n == 2:\n  return 'a'\n else:\n  return 3")
     
     py.test.raises(AnnotatorError, compile_function, f, [int])
+
+def test_basicexternal_attribute():
+    from pypy.rpython.ootypesystem.bltregistry import BasicExternal
+
+    class A(BasicExternal):
+        pass
+    
+    def f():
+        return A().f
+
+    py.test.raises(NoSuchAttrError, compile_function, f, [])
+
+    def g():
+        return A().g()
+
+    py.test.raises(NoSuchAttrError, compile_function, g, [])



More information about the Pypy-commit mailing list