[pypy-commit] pypy remove-array-smm: merge default

fijal noreply at buildbot.pypy.org
Sun May 12 18:30:23 CEST 2013


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: remove-array-smm
Changeset: r64012:dc1a1bfd938e
Date: 2013-05-12 16:24 +0200
http://bitbucket.org/pypy/pypy/changeset/dc1a1bfd938e/

Log:	merge default

diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -803,7 +803,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):
@@ -812,11 +811,13 @@
     d = {}
     exec func_code.compile() in d
     f = d['f']
+    f.func_defaults = unbound_meth.func_defaults
+    f.func_doc = unbound_meth.func_doc
     f.__module__ = func.__module__
     # necessary for unique identifiers for pickling
     f.func_name = func.func_name
     if unwrap_spec is None:
-        unwrap_spec = getattr(func, 'unwrap_spec', {})
+        unwrap_spec = getattr(unbound_meth, 'unwrap_spec', {})
     else:
         assert isinstance(unwrap_spec, dict)
         unwrap_spec = unwrap_spec.copy()
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,39 @@
 
     def test_interpindirect2app(self):
         space = self.space
+
         class BaseA(W_Root):
             def method(self, space, x):
+                "This is a method"
+                pass
+
+            def method_with_default(self, space, x=5):
+                pass
+
+            @gateway.unwrap_spec(x=int)
+            def method_with_unwrap_spec(self, space, x):
                 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)
+
+            def method_with_unwrap_spec(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)
+
+            def method_with_unwrap_spec(self, space, x):
+                return space.wrap(x + 1)
+
         class FakeTypeDef(object):
             rawdict = {}
             bases = {}
@@ -163,6 +184,23 @@
         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
 
+        doc = space.str_w(space.getattr(w_c, space.wrap('__doc__')))
+        assert doc == "This is a method"
+
+        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
+
+        meth_with_unwrap_spec = gateway.interpindirect2app(
+            BaseA.method_with_unwrap_spec)
+        w_e = space.wrap(meth_with_unwrap_spec)
+        assert space.int_w(space.call_function(w_e, w_a, space.wrap(4))) == 4 + 2
+
     def test_interp2app_unwrap_spec(self):
         space = self.space
         w = space.wrap


More information about the pypy-commit mailing list