[pypy-svn] r76405 - in pypy/trunk/pypy/rlib: . test

fijal at codespeak.net fijal at codespeak.net
Fri Jul 30 19:07:01 CEST 2010


Author: fijal
Date: Fri Jul 30 19:06:59 2010
New Revision: 76405

Modified:
   pypy/trunk/pypy/rlib/objectmodel.py
   pypy/trunk/pypy/rlib/test/test_objectmodel.py
Log:
An enforceargs decorator


Modified: pypy/trunk/pypy/rlib/objectmodel.py
==============================================================================
--- pypy/trunk/pypy/rlib/objectmodel.py	(original)
+++ pypy/trunk/pypy/rlib/objectmodel.py	Fri Jul 30 19:06:59 2010
@@ -82,6 +82,17 @@
         
 specialize = _Specialize()
 
+def enforceargs(*args):
+    """ Decorate a function with forcing of RPython-level types on arguments.
+    None means no enforcing.
+
+    XXX shouldn't we also add asserts in function body?
+    """
+    def decorator(f):
+        f._annenforceargs_ = args
+        return f
+    return decorator
+
 # ____________________________________________________________
 
 class Symbolic(object):

Modified: pypy/trunk/pypy/rlib/test/test_objectmodel.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_objectmodel.py	(original)
+++ pypy/trunk/pypy/rlib/test/test_objectmodel.py	Fri Jul 30 19:06:59 2010
@@ -404,6 +404,13 @@
 
     assert f._annspecialcase_ == 'specialize:arg(1)'
 
+def test_enforceargs_decorator():
+    @enforceargs(int, str, None)
+    def f(a, b, c):
+        pass
+
+    assert f._annenforceargs_ == (int, str, None)
+
 def getgraph(f, argtypes):
     from pypy.translator.translator import TranslationContext, graphof
     from pypy.translator.backendopt.all import backend_optimizations



More information about the Pypy-commit mailing list