Author: Antonio Cuni <[email protected]>
Branch: better-enforceargs
Changeset: r56118:2c7878b2ed50
Date: 2012-07-18 01:08 +0200
http://bitbucket.org/pypy/pypy/changeset/2c7878b2ed50/

Log:    make sure to preserve the func_dict of the original function: this
        is needed if we decorate a func with both @enforceargs and e.g.
        @jit. Also, it now plays well with @specialize only if @specialize
        is seen *before* @enforceargs

diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -165,6 +165,7 @@
         exec src.compile() in mydict
         result = mydict[f.func_name]
         result.func_defaults = f.func_defaults
+        result.func_dict.update(f.func_dict)
         result._annenforceargs_ = types
         return result
     return decorator
diff --git a/pypy/rlib/rgc.py b/pypy/rlib/rgc.py
--- a/pypy/rlib/rgc.py
+++ b/pypy/rlib/rgc.py
@@ -138,8 +138,8 @@
         return hop.genop(opname, vlist, resulttype = hop.r_result.lowleveltype)
 
 @jit.oopspec('list.ll_arraycopy(source, dest, source_start, dest_start, 
length)')
+@enforceargs(None, None, int, int, int)
 @specialize.ll()
-@enforceargs(None, None, int, int, int)
 def ll_arraycopy(source, dest, source_start, dest_start, length):
     from pypy.rpython.lltypesystem.lloperation import llop
     from pypy.rlib.objectmodel import keepalive_until_here
diff --git a/pypy/rlib/test/test_objectmodel.py 
b/pypy/rlib/test/test_objectmodel.py
--- a/pypy/rlib/test/test_objectmodel.py
+++ b/pypy/rlib/test/test_objectmodel.py
@@ -421,8 +421,10 @@
     @enforceargs(int, str, None)
     def f(a, b, c):
         return a, b, c
+    f.foo = 'foo'
     assert f._annenforceargs_ == (int, str, None)
     assert f.func_name == 'f'
+    assert f.foo == 'foo'
     assert f(1, 'hello', 42) == (1, 'hello', 42)
     exc = py.test.raises(TypeError, "f(1, 2, 3)")
     assert exc.value.message == "f argument number 2 must be of type <type 
'str'>"
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to