[pypy-svn] r37183 - in pypy/dist/pypy/annotation: . test

pedronis at codespeak.net pedronis at codespeak.net
Tue Jan 23 13:09:39 CET 2007


Author: pedronis
Date: Tue Jan 23 13:09:31 2007
New Revision: 37183

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/annotation/test/test_annrpython.py
Log:
(arre, pedronis) support attaching _attrs_ to pbcs to enforce assumptions about attribute being present.



Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Tue Jan 23 13:09:31 2007
@@ -11,7 +11,7 @@
      SomeInteger, SomeExternalObject, SomeOOInstance, TLS, SomeAddress, \
      SomeUnicodeCodePoint, SomeOOStaticMeth, s_None, s_ImpossibleValue, \
      SomeLLADTMeth, SomeBool, SomeTuple, SomeOOClass, SomeImpossibleValue, \
-     SomeList, SomeObject, SomeWeakGcAddress
+     SomeList, SomeObject, SomeWeakGcAddress, HarmlesslyBlocked
 from pypy.annotation.classdef import ClassDef, InstanceSource
 from pypy.annotation.listdef import ListDef, MOST_GENERAL_LISTDEF
 from pypy.annotation.dictdef import DictDef, MOST_GENERAL_DICTDEF
@@ -587,7 +587,15 @@
         if change:
             for position in attrfamily.read_locations:
                 self.annotator.reflowfromposition(position)
-                
+
+        if isinstance(s_result, SomeImpossibleValue):
+            for desc in descs:
+                attrs = desc.read_attribute('_attrs_')
+                if isinstance(attrs, Constant):
+                    attrs = attrs.value
+                if attr in attrs:
+                    raise HarmlesslyBlocked("getattr on enforced attr")
+
         return s_result
 
     def pbc_call(self, pbc, args, emulated=None):

Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py	Tue Jan 23 13:09:31 2007
@@ -2423,6 +2423,28 @@
                 from pypy.annotation.classdef import NoSuchSlotError
                 py.test.raises(NoSuchSlotError, a.build_types, fun, [int])
 
+    def test_pbc_enforce_attrs(self):
+        class F(object):
+            _attrs_ = ['foo',]
+
+            def _freeze_(self):
+                return True
+
+        p1 = F()
+        p2 = F()
+
+        def g(): pass
+
+        def f(x):
+            if x:
+                p = p1
+            else:
+                p = p2
+            g()
+            return p.foo
+
+        a = self.RPythonAnnotator()
+        a.build_types(f, [bool])
 
     def test_float_cmp(self):
         def fun(x, y):



More information about the Pypy-commit mailing list