[pypy-svn] r14551 - in pypy/dist/pypy/rpython: . test
arigo at codespeak.net
arigo at codespeak.net
Tue Jul 12 19:20:57 CEST 2005
Author: arigo
Date: Tue Jul 12 19:20:56 2005
New Revision: 14551
Modified:
pypy/dist/pypy/rpython/rclass.py
pypy/dist/pypy/rpython/test/test_rclass.py
Log:
staticmethod support in the rtyper.
Modified: pypy/dist/pypy/rpython/rclass.py
==============================================================================
--- pypy/dist/pypy/rpython/rclass.py (original)
+++ pypy/dist/pypy/rpython/rclass.py Tue Jul 12 19:20:56 2005
@@ -234,6 +234,12 @@
else:
# setup class attributes: for each attribute name at the level
# of 'self', look up its value in the subclass rsubcls
+ def assign(mangled_name, value):
+ if isinstance(value, staticmethod):
+ value = value.__get__(42) # staticmethod => bare function
+ llvalue = r.convert_const(value)
+ setattr(vtable, mangled_name, llvalue)
+
mro = list(rsubcls.classdef.getmro())
for fldname in self.clsfields:
mangled_name, r = self.clsfields[fldname]
@@ -242,8 +248,7 @@
for clsdef in mro:
if fldname in clsdef.cls.__dict__:
value = clsdef.cls.__dict__[fldname]
- llvalue = r.convert_const(value)
- setattr(vtable, mangled_name, llvalue)
+ assign(mangled_name, value)
break
# extra PBC attributes
for (access_set, attr), (mangled_name, r) in self.pbcfields.items():
@@ -256,8 +261,7 @@
if attr not in clsdef.cls.__dict__:
continue
thisattrvalue = clsdef.cls.__dict__[attr]
- llvalue = r.convert_const(thisattrvalue)
- setattr(vtable, mangled_name, llvalue)
+ assign(mangled_name, thisattrvalue)
break
# then initialize the 'super' portion of the vtable
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 Tue Jul 12 19:20:56 2005
@@ -168,3 +168,12 @@
assert interpret(g, [0], view=False, viewbefore=False) == True
assert interpret(g, [1], view=False, viewbefore=False) == True
+def test_staticmethod():
+ class A(object):
+ f = staticmethod(lambda x, y: x*y)
+ def f():
+ a = A()
+ return a.f(6, 7)
+ res = interpret(f, [])
+ assert res == 42
+
More information about the Pypy-commit
mailing list