[pypy-commit] pypy better-enforceargs: handle defaults
antocuni
noreply at buildbot.pypy.org
Tue Jul 17 18:10:57 CEST 2012
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: better-enforceargs
Changeset: r56107:091f47c1126d
Date: 2012-07-17 17:55 +0200
http://bitbucket.org/pypy/pypy/changeset/091f47c1126d/
Log: handle defaults
diff --git a/pypy/rlib/objectmodel.py b/pypy/rlib/objectmodel.py
--- a/pypy/rlib/objectmodel.py
+++ b/pypy/rlib/objectmodel.py
@@ -141,7 +141,7 @@
'typecheck': typecheck}
exec src.compile() in mydict
result = mydict[f.func_name]
- # XXX defaults
+ result.func_defaults = f.func_defaults
result._annenforceargs_ = types
return result
return decorator
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
@@ -427,7 +427,12 @@
py.test.raises(TypeError, "f(1, 2, 3)")
py.test.raises(TypeError, "f('hello', 'world', 3)")
-
+def test_enforceargs_defaults():
+ @enforceargs(int, int)
+ def f(a, b=40):
+ return a+b
+ assert f(2) == 42
+
def getgraph(f, argtypes):
from pypy.translator.translator import TranslationContext, graphof
More information about the pypy-commit
mailing list