[pypy-svn] r26765 - in pypy/dist/pypy: annotation annotation/test rpython/test

pedronis at codespeak.net pedronis at codespeak.net
Thu May 4 17:26:23 CEST 2006


Author: pedronis
Date: Thu May  4 17:26:21 2006
New Revision: 26765

Modified:
   pypy/dist/pypy/annotation/description.py
   pypy/dist/pypy/annotation/test/test_annrpython.py
   pypy/dist/pypy/rpython/test/test_rclass.py
Log:
test and fix about _mixin_



Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py	(original)
+++ pypy/dist/pypy/annotation/description.py	Thu May  4 17:26:21 2006
@@ -336,7 +336,7 @@
                 if getattr(b1, '_mixin_', False):
                     assert b1.__bases__ == () or b1.__bases__ == (object,), (
                         "mixin class %r should have no base" % (b1,))
-                    self.add_sources_for_class(b1)
+                    self.add_sources_for_class(b1, mixin=True)
                 else:
                     assert base is object, ("multiple inheritance only supported "
                                             "with _mixin_: %r" % (cls,))
@@ -346,7 +346,7 @@
             if base is not object:
                 self.basedesc = bookkeeper.getdesc(base)
 
-    def add_sources_for_class(self, cls):
+    def add_sources_for_class(self, cls, mixin=False):
         for name, value in cls.__dict__.items():
             ## -- useless? -- ignore some special attributes
             ##if name.startswith('_') and not isinstance(value, types.FunctionType):
@@ -355,7 +355,7 @@
                 # for debugging
                 if not hasattr(value, 'class_'):
                     value.class_ = self.pyobj # remember that this is really a method
-                if self.specialize:
+                if self.specialize or mixin:
                     # make a custom funcdesc that specializes on its first
                     # argument (i.e. 'self').
                     from pypy.annotation.specialize import specialize_argtype

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	Thu May  4 17:26:21 2006
@@ -2002,6 +2002,35 @@
         assert s.is_constant()
         assert s.const == 0
 
+    def test_mixin(self):
+        class Mixin(object):
+            _mixin_ = True
+
+            def m(self, v):
+                return v
+
+        class Base(object):
+            pass
+
+        class A(Base, Mixin):
+            pass
+
+        class B(Base, Mixin):
+            pass
+
+        def f():
+            a = A()
+            v0 = a.m(2)
+            b = B()
+            v1 = b.m('x')
+            return v0, v1
+
+        a = self.RPythonAnnotator()
+        s = a.build_types(f, [])
+        assert isinstance(s.items[0], annmodel.SomeInteger)
+        assert isinstance(s.items[1], annmodel.SomeChar)        
+        
+
 def g(n):
     return [0,1,2,n]
 

Modified: pypy/dist/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rclass.py	Thu May  4 17:26:21 2006
@@ -432,7 +432,32 @@
         res = interpret(f, [], type_system=self.ts)
         assert res == 1
 
-   
+    def test_mixin(self):
+        class Mixin(object):
+            _mixin_ = True
+
+            def m(self, v):
+                return v
+
+        class Base(object):
+            pass
+
+        class A(Base, Mixin):
+            pass
+
+        class B(Base, Mixin):
+            pass
+
+        def f():
+            a = A()
+            v0 = a.m(2)
+            b = B()
+            v1 = b.m('x')
+            return v0, v1
+
+        res = interpret(f, [], type_system=self.ts)
+        assert typeOf(res.item0) == Signed
+
 
 class TestLltype(BaseTestRclass):
 



More information about the Pypy-commit mailing list