[pypy-svn] r34736 - in pypy/dist/pypy: annotation/test rpython
arigo at codespeak.net
arigo at codespeak.net
Sat Nov 18 17:51:30 CET 2006
Author: arigo
Date: Sat Nov 18 17:51:29 2006
New Revision: 34736
Modified:
pypy/dist/pypy/annotation/test/test_annrpython.py
pypy/dist/pypy/rpython/controllerentry.py
Log:
(pedronis, arigo)
setattr support too. (Check-in message will come one day if it proves
to not be all non-sense...)
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 Sat Nov 18 17:51:29 2006
@@ -2409,8 +2409,10 @@
"Imagine some magic here to have a foo attribute on instances"
def fun():
+ lst = []
c = C()
- return c.foo
+ c.foo = lst # side-effect on lst! well, it's a test
+ return c.foo, lst[0]
class C_Controller(Controller):
knowntype = C
@@ -2421,13 +2423,16 @@
def get_foo(self, obj):
return obj + "2"
+ def set_foo(self, obj, value):
+ value.append(obj)
+
class Entry(ControllerEntry):
_about_ = C
_controller_ = C_Controller
a = self.RPythonAnnotator(policy=policy.AnnotatorPolicy())
s = a.build_types(fun, [])
- assert s.const == "42"
+ assert s.const == ("42", "4")
def g(n):
Modified: pypy/dist/pypy/rpython/controllerentry.py
==============================================================================
--- pypy/dist/pypy/rpython/controllerentry.py (original)
+++ pypy/dist/pypy/rpython/controllerentry.py Sat Nov 18 17:51:29 2006
@@ -33,6 +33,13 @@
return getattr(self, 'get_' + attr)(obj)
getattr._annspecialcase_ = 'specialize:arg(2)'
+ def ctrl_setattr(self, s_obj, s_attr, s_value):
+ return delegate(self.setattr, s_obj, s_attr, s_value)
+
+ def setattr(self, obj, attr, value):
+ return getattr(self, 'set_' + attr)(obj, value)
+ setattr._annspecialcase_ = 'specialize:arg(2)'
+
def delegate(boundmethod, *args_s):
bk = getbookkeeper()
@@ -56,6 +63,10 @@
assert s_attr.is_constant()
return s_cin.controller.ctrl_getattr(s_cin.s_real_obj, s_attr)
+ def setattr(s_cin, s_attr, s_value):
+ assert s_attr.is_constant()
+ s_cin.controller.ctrl_setattr(s_cin.s_real_obj, s_attr, s_value)
+
class __extend__(pairtype(SomeControlledInstance, SomeControlledInstance)):
More information about the Pypy-commit
mailing list