[pypy-commit] pypy remove-string-smm: Add support for func_defaults to interpdirect2app.
hodgestar
noreply at buildbot.pypy.org
Tue Apr 16 21:16:53 CEST 2013
Author: Simon Cross <hodgestar at gmail.com>
Branch: remove-string-smm
Changeset: r63422:264b4a12d787
Date: 2013-04-16 21:00 +0200
http://bitbucket.org/pypy/pypy/changeset/264b4a12d787/
Log: Add support for func_defaults to interpdirect2app.
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -809,7 +809,6 @@
args = inspect.getargs(func.func_code)
if args.varargs or args.keywords:
raise TypeError("Varargs and keywords not supported in unwrap_spec")
- assert not func.func_defaults
argspec = ', '.join([arg for arg in args.args[1:]])
func_code = py.code.Source("""
def f(w_obj, %(args)s):
@@ -818,6 +817,7 @@
d = {}
exec func_code.compile() in d
f = d['f']
+ f.func_defaults = unbound_meth.func_defaults
f.__module__ = func.__module__
# necessary for unique identifiers for pickling
f.func_name = func.func_name
diff --git a/pypy/interpreter/test/test_gateway.py b/pypy/interpreter/test/test_gateway.py
--- a/pypy/interpreter/test/test_gateway.py
+++ b/pypy/interpreter/test/test_gateway.py
@@ -135,18 +135,28 @@
def test_interpindirect2app(self):
space = self.space
+
class BaseA(W_Root):
def method(self, space, x):
pass
+ def method_with_default(self, space, x=5):
+ pass
+
class A(BaseA):
def method(self, space, x):
return space.wrap(x + 2)
+ def method_with_default(self, space, x):
+ return space.wrap(x + 2)
+
class B(BaseA):
def method(self, space, x):
return space.wrap(x + 1)
+ def method_with_default(self, space, x):
+ return space.wrap(x + 1)
+
class FakeTypeDef(object):
rawdict = {}
bases = {}
@@ -163,6 +173,15 @@
assert space.int_w(space.call_function(w_c, w_a, space.wrap(1))) == 1 + 2
assert space.int_w(space.call_function(w_c, w_b, space.wrap(-10))) == -10 + 1
+ meth_with_default = gateway.interpindirect2app(
+ BaseA.method_with_default, {'x': int})
+ w_d = space.wrap(meth_with_default)
+
+ assert space.int_w(space.call_function(w_d, w_a, space.wrap(4))) == 4 + 2
+ assert space.int_w(space.call_function(w_d, w_b, space.wrap(-10))) == -10 + 1
+ assert space.int_w(space.call_function(w_d, w_a)) == 5 + 2
+ assert space.int_w(space.call_function(w_d, w_b)) == 5 + 1
+
def test_interp2app_unwrap_spec(self):
space = self.space
w = space.wrap
More information about the pypy-commit
mailing list