[pypy-svn] r37998 - in pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem: . test
fijal at codespeak.net
fijal at codespeak.net
Tue Feb 6 11:59:39 CET 2007
Author: fijal
Date: Tue Feb 6 11:59:36 2007
New Revision: 37998
Modified:
pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/bltregistry.py
pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/test/test_bltann.py
Log:
Another merge
Modified: pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/bltregistry.py
==============================================================================
--- pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/bltregistry.py (original)
+++ pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/bltregistry.py Tue Feb 6 11:59:36 2007
@@ -50,6 +50,28 @@
return tuple([typeof(i) for i in val])
return type(val)
+def load_dict_args(func, args):
+ code = func.func_code
+ if not func.func_defaults:
+ defs = []
+ else:
+ defs = func.func_defaults
+ num_args = code.co_argcount
+ assert(num_args < len(defs) + len(args), "Not enough information for describing method")
+
+ for arg in xrange(1, code.co_argcount - len(defs)):
+ assert code.co_varnames[arg] in args, "Don't have type for arg %s" % code.co_varnames[arg]
+
+ arg_pass = []
+ start_pos = code.co_argcount - len(defs)
+ for arg in xrange(1, code.co_argcount):
+ varname = code.co_varnames[arg]
+ if varname in args:
+ arg_pass.append((varname, args[varname]))
+ else:
+ arg_pass.append((varname, typeof(defs[arg - start_pos])))
+ return arg_pass
+
class BasicExternal(object):
__metaclass__ = BasicMetaExternal
__self__ = None
@@ -59,25 +81,11 @@
def described(retval=None, args={}):
def decorator(func):
- code = func.func_code
- if not func.func_defaults:
- defs = []
+ if isinstance(args, dict):
+ arg_pass = load_dict_args(func, args)
else:
- defs = func.func_defaults
-
- assert(code.co_argcount < len(defs) + len(args), "Not enough information for describing method")
-
- for arg in xrange(1, code.co_argcount - len(defs)):
- assert code.co_varnames[arg] in args, "Don't have type for arg %s" % code.co_varnames[arg]
-
- arg_pass = []
- start_pos = code.co_argcount - len(defs)
- for arg in xrange(1, code.co_argcount):
- varname = code.co_varnames[arg]
- if varname in args:
- arg_pass.append((varname, args[varname]))
- else:
- arg_pass.append((varname, typeof(defs[arg - start_pos])))
+ assert isinstance(args, list)
+ arg_pass = args
func._method = (func.__name__, MethodDesc(arg_pass, retval))
return func
return decorator
@@ -96,7 +104,9 @@
def __call__(self, *args):
args = args[1:]
- assert len(self.s_args) == len(args)
+ assert len(self.s_args) == len(args),\
+ "Function %s expects %d arguments, got %d instead" % (self.name,
+ len(self.s_args), len(args))
for num, (arg, expected) in enumerate(zip(args, self.s_args)):
res = unionof(arg, expected)
assert expected.contains(res)
Modified: pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/test/test_bltann.py
==============================================================================
--- pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/test/test_bltann.py (original)
+++ pypy/branch/pytrunkmerge/pypy/rpython/ootypesystem/test/test_bltann.py Tue Feb 6 11:59:36 2007
@@ -140,3 +140,27 @@
s = a.build_types(callback_field, [])
assert isinstance(s, annmodel.SomeGenericCallable)
assert a.translator._graphof(callback)
+
+def test_callback_field_bound_method():
+ class A:
+ def x(self, i):
+ return float(i)
+
+ aa = A()
+
+ def callback(x):
+ return 8.3 + x
+
+ def callback_field(i):
+ a = CD()
+ if i:
+ a.callback_field = aa.x
+ else:
+ a.callback_field = callback
+ return a.callback_field(i+1)
+
+ res = interpret(callback_field, [1], type_system="ootype")
+ assert res == 2.0
+ assert isinstance(res, float)
+ res = interpret(callback_field, [0], type_system="ootype")
+ assert res == 8.3
More information about the Pypy-commit
mailing list