[pypy-svn] r15278 - in pypy/dist/pypy: annotation translator translator/test

arigo at codespeak.net arigo at codespeak.net
Thu Jul 28 19:26:01 CEST 2005


Author: arigo
Date: Thu Jul 28 19:25:55 2005
New Revision: 15278

Modified:
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
* Hide AttributeErrors in the annotator, using the can_only_throw mechanism.
* Bug fix in said mechanism.
* Test.


Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Thu Jul 28 19:25:55 2005
@@ -137,6 +137,7 @@
             getbookkeeper().warning('getattr(%r, %r) is not RPythonic enough' %
                                     (obj, s_attr))
         return SomeObject()
+    getattr.can_only_throw = []
 
     def bindcallables(obj, classdef):
         return obj   # default unbound __get__ implementation
@@ -375,6 +376,7 @@
                 ins.classdef.check_missing_attribute_update(attr)
             return s_result
         return SomeObject()
+    getattr.can_only_throw = []
 
     def setattr(ins, s_attr, s_value):
         if s_attr.is_constant() and isinstance(s_attr.const, str):
@@ -413,6 +415,7 @@
     def getattr(pbc, s_attr):
         bookkeeper = getbookkeeper()
         return bookkeeper.pbc_getattr(pbc, s_attr)
+    getattr.can_only_throw = []
 
     def setattr(pbc, s_attr, s_value):
         getbookkeeper().warning("setattr not wanted on %r" % (pbc,))

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Thu Jul 28 19:25:55 2005
@@ -459,9 +459,13 @@
 
             if can_only_throw is not None:
                 candidates = can_only_throw
-                exits = [block.exits[0]]
-                for link in block.exits[1:]:
+                candidate_exits = exits
+                exits = []
+                for link in candidate_exits:
                     case = link.exitcase
+                    if case is None:
+                        exits.append(link)
+                        continue
                     covered = [c for c in candidates if issubclass(c, case)]
                     if covered:
                         exits.append(link)

Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py	Thu Jul 28 19:25:55 2005
@@ -1481,6 +1481,24 @@
         s = a.build_types(f, [bool])
         assert s == annmodel.SomeString(can_be_None=True)
 
+    def test_dont_see_AttributeError_clause(self):
+        class Stuff:
+            def _freeze_(self):
+                return True
+            def createcompiler(self):
+                try:
+                    return self.default_compiler
+                except AttributeError:
+                    compiler = "yadda"
+                    self.default_compiler = compiler
+                    return compiler
+        stuff = Stuff()
+        stuff.default_compiler = 123
+        def f():
+            return stuff.createcompiler()
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [])
+        assert s == a.bookkeeper.immutablevalue(123)
 
 def g(n):
     return [0,1,2,n]



More information about the Pypy-commit mailing list