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

cfbolz at codespeak.net cfbolz at codespeak.net
Fri Dec 9 15:23:05 CET 2005


Author: cfbolz
Date: Fri Dec  9 15:23:04 2005
New Revision: 20937

Modified:
   pypy/dist/pypy/annotation/description.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
(johahn, cfbolz):

make sure that __del__ methods are annotated if found.



Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py	(original)
+++ pypy/dist/pypy/annotation/description.py	Fri Dec  9 15:23:04 2005
@@ -387,6 +387,13 @@
             for attr in self.classdict:
                 classsources[attr] = self    # comes from this ClassDesc
             classdef.setup(classsources)
+            # look for a __del__ method and annotate it if it's there
+            if '__del__' in self.classdict:
+                from pypy.annotation.model import s_None, SomeInstance
+                s_func = self.s_read_attribute('__del__')
+                args_s = [SomeInstance(classdef)]
+                s = self.bookkeeper.emulate_pbc_call(None, s_func, args_s)
+                assert s_None.contains(s)
             return classdef
 
     def getuniqueclassdef(self):

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	Fri Dec  9 15:23:04 2005
@@ -1884,6 +1884,39 @@
         s = a.build_types(f, [])
         assert s.knowntype == int
 
+    def test_annotate__del__(self):
+        class A(object):
+            def __init__(self):
+                self.a = 2
+            def __del__(self):
+                self.a = 1
+        def f():
+            return A().a
+        a = self.RPythonAnnotator()
+        t = a.translator
+        s = a.build_types(f, [])
+        assert s.knowntype == int
+        graph = tgraphof(t, A.__del__.im_func)
+        assert graph.startblock in a.annotated
+
+    def test_annotate__del__baseclass(self):
+        class A(object):
+            def __init__(self):
+                self.a = 2
+            def __del__(self):
+                self.a = 1
+        class B(A):
+            def __init__(self):
+                self.a = 3
+        def f():
+            return B().a
+        a = self.RPythonAnnotator()
+        t = a.translator
+        s = a.build_types(f, [])
+        assert s.knowntype == int
+        graph = tgraphof(t, A.__del__.im_func)
+        assert graph.startblock in a.annotated
+
 def g(n):
     return [0,1,2,n]
 



More information about the Pypy-commit mailing list