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

arigo at codespeak.net arigo at codespeak.net
Sun Jul 3 18:09:53 CEST 2005


Author: arigo
Date: Sun Jul  3 18:09:49 2005
New Revision: 14159

Modified:
   pypy/dist/pypy/annotation/classdef.py
   pypy/dist/pypy/rpython/rclass.py
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
- more tests about methods in the rtyper, fixed by (don't blink) a new
  line in rclass.py that filters the method PBCs in the same way that
  the annotator does, i.e. by ignoring all methods that can't possibly be
  called at this point, either because they belong to unrelated classes, or
  because they belong to a parent class and we see that they are overridden.

- a special case for built-in types, seen in faking



Modified: pypy/dist/pypy/annotation/classdef.py
==============================================================================
--- pypy/dist/pypy/annotation/classdef.py	(original)
+++ pypy/dist/pypy/annotation/classdef.py	Sun Jul  3 18:09:49 2005
@@ -315,7 +315,7 @@
                     return None
         return None
 
-    def matching(self, pbc, name):
+    def matching(self, pbc, name=None):
         d = {}
         uplookup = None
         upfunc = None
@@ -341,7 +341,7 @@
             # PBC dictionary to track more precisely with which 'self' the
             # method is called.
             d[upfunc] = self
-        elif meth:
+        elif meth and name is not None:
             self.check_missing_attribute_update(name)
         if d:
             return SomePBC(d)

Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py	(original)
+++ pypy/dist/pypy/rpython/rclass.py	Sun Jul  3 18:09:49 2005
@@ -156,6 +156,7 @@
         #    as MethodType has a custom __get__ too and we don't support
         #    it, it's a very bad idea anyway.
         if isinstance(s_value, annmodel.SomePBC):
+            s_value = self.classdef.matching(s_value)
             debound = {}
             count = 0
             for x, classdef in s_value.prebuiltinstances.items():

Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Sun Jul  3 18:09:49 2005
@@ -41,6 +41,9 @@
                     choice = MethodOfFrozenPBCRepr
                 else:
                     raise TyperError("don't know about callable %r" % (x,))
+            elif type(x) is type and x.__module__ == '__builtin__':
+                # special case for built-in types, seen in faking
+                choice = getPyObjRepr
             else:
                 # frozen object
                 choice = getFrozenPBCRepr
@@ -63,6 +66,9 @@
 
 # ____________________________________________________________
 
+def getPyObjRepr(rtyper, s_pbc):
+    return robject.pyobj_repr
+
 
 def getFrozenPBCRepr(rtyper, s_pbc):
     if len(s_pbc.prebuiltinstances) <= 1:

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Sun Jul  3 18:09:49 2005
@@ -37,6 +37,10 @@
     def m(self, x):
         return self.z - x
 
+class MyStrangerSubclass(MyBase):
+    def m(self, x, y):
+        return x*y
+
 def test_method_call():
     def f(a, b):
         obj = MyBase()
@@ -58,17 +62,51 @@
     res = interpret(f, [-1, 2.3])
     assert res == -3.3
 
+def test_stranger_subclass_1():
+    def f1():
+        obj = MyStrangerSubclass()
+        obj.z = 100
+        return obj.m(6, 7)
+    res = interpret(f1, [])
+    assert res == 42
+
+def test_stranger_subclass_2():
+    def f2():
+        obj = MyStrangerSubclass()
+        obj.z = 100
+        return obj.m(6, 7) + MyBase.m(obj, 58)
+    res = interpret(f2, [])
+    assert res == 200
+
 
 class MyBaseWithInit:
     def __init__(self, a):
         self.a1 = a
 
+class MySubclassWithInit(MyBaseWithInit):
+    def __init__(self, a, b):
+        MyBaseWithInit.__init__(self, a)
+        self.b1 = b
+
 def test_class_init():
     def f(a):
         instance = MyBaseWithInit(a)
         return instance.a1
     assert interpret(f, [5]) == 5
 
+def test_class_init_2():
+    def f(a, b):
+        instance = MySubclassWithInit(a, b)
+        return instance.a1 * instance.b1
+    assert interpret(f, [6, 7]) == 42
+
+def test_class_calling_init():
+    def f():
+        instance = MySubclassWithInit(1, 2)
+        instance.__init__(3, 4)
+        return instance.a1 * instance.b1
+    assert interpret(f, []) == 12
+
 
 class Freezing:
     def _freeze_(self):



More information about the Pypy-commit mailing list