[pypy-svn] r13557 - in pypy/dist/pypy/rpython: . test

arigo at codespeak.net arigo at codespeak.net
Fri Jun 17 22:38:43 CEST 2005


Author: arigo
Date: Fri Jun 17 22:38:41 2005
New Revision: 13557

Modified:
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
Replace unbound methods (as they can appear as Constants in flow graphs) with
bare functions, like the annotator generally does.



Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Fri Jun 17 22:38:41 2005
@@ -240,6 +240,8 @@
 ##                assert not shape_stst, "XXX not implemented"
 
     def convert_const(self, value):
+        if isinstance(value, types.MethodType) and value.im_self is None:
+            value = value.im_func   # unbound method -> bare function
         if value not in self.function_signatures:
             raise TyperError("%r not in %r" % (value,
                                                self.s_pbc.prebuiltinstances))

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	Fri Jun 17 22:38:41 2005
@@ -119,3 +119,11 @@
     assert res == 6
     res = interpret(f, [-1])
     assert res == 5
+
+def test_unbound_method():
+    def f():
+        inst = MySubclass()
+        inst.z = 40
+        return MyBase.m(inst, 2)
+    res = interpret(f, [])
+    assert res == 42



More information about the Pypy-commit mailing list