Author: Armin Rigo <[email protected]>
Branch: py3k-kwonly-builtin
Changeset: r86352:06fb039274e4
Date: 2016-08-20 17:55 +0200
http://bitbucket.org/pypy/pypy/changeset/06fb039274e4/
Log: Tests, fix
diff --git a/pypy/interpreter/gateway.py b/pypy/interpreter/gateway.py
--- a/pypy/interpreter/gateway.py
+++ b/pypy/interpreter/gateway.py
@@ -481,7 +481,7 @@
self.unwrap.append("space.truncatedint_w(%s)" % (self.nextarg(),))
def visit_kwonly(self, typ):
- self.unwrap.append("None")
+ raise FastFuncNotSupported
def make_fastfunc(unwrap_spec, func):
unwrap_info = UnwrapSpec_FastFunc_Unwrap()
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
@@ -809,6 +809,71 @@
w_res = space.call_args(w_g, args)
assert space.eq_w(w_res, space.newbytes('foo'))
+ def test_unwrap_spec_kwonly(self):
+ space = self.space
+ def g(space, w_x, __kwonly__, w_y):
+ return space.sub(w_x, w_y)
+ w_g = space.wrap(gateway.interp2app_temp(g))
+ w = space.wrap
+ w1 = w(1)
+
+ for i in range(4):
+ a = argument.Arguments(space, [w1, w1, w1])
+ py.test.raises(gateway.OperationError, space.call_args, w_g, a)
+ py.test.raises(gateway.OperationError, space.call_function, w_g,
+ *(i * (w1,)))
+
+ args = argument.Arguments(space, [w(1)],
+ w_starstararg = w({'y': 10}))
+ assert space.eq_w(space.call_args(w_g, args), w(-9))
+ args = argument.Arguments(space, [],
+ w_starstararg = w({'x': 2, 'y': 10}))
+ assert space.eq_w(space.call_args(w_g, args), w(-8))
+
+ def test_unwrap_spec_kwonly_default(self):
+ space = self.space
+ @gateway.unwrap_spec(w_x2=WrappedDefault(50), y2=int)
+ def g(space, w_x1, w_x2, __kwonly__, w_y1, y2=200):
+ return space.sub(space.sub(w_x1, w_x2),
+ space.sub(w_y1, w(y2)))
+ w_g = space.wrap(gateway.interp2app_temp(g))
+ w = space.wrap
+ w1 = w(1)
+
+ for i in range(6):
+ py.test.raises(gateway.OperationError, space.call_function, w_g,
+ *(i * (w1,)))
+
+ def expected(x1, x2=50, y1="missing", y2=200):
+ return (x1 - x2) - (y1 - y2)
+
+ def check(*args, **kwds):
+ a = argument.Arguments(space, [], w_stararg = w(args),
+ w_starstararg = w(kwds))
+ w_res = space.call_args(w_g, a)
+ assert space.eq_w(w_res, w(expected(*args, **kwds)))
+
+ del kwds['y1']
+ a = argument.Arguments(space, [], w_stararg = w(args),
+ w_starstararg = w(kwds))
+ py.test.raises(gateway.OperationError, space.call_args, w_g, a)
+
+ args += (1234,)
+ a = argument.Arguments(space, [], w_stararg = w(args),
+ w_starstararg = w(kwds))
+ py.test.raises(gateway.OperationError, space.call_args, w_g, a)
+
+ check(5, y1=1234)
+ check(5, 1, y1=1234)
+ check(5, x2=1, y1=1234)
+ check(5, y1=1234, y2=343)
+ check(5, 1, y1=1234, y2=343)
+ check(5, x2=1, y1=1234, y2=343)
+ check(x1=5, y1=1234, )
+ check(x1=5, x2=1, y1=1234, )
+ check(x1=5, y1=1234, y2=343)
+ check(x1=5, x2=1, y1=1234, y2=343)
+
class AppTestPyTestMark:
@py.test.mark.unlikely_to_exist
diff --git a/pypy/interpreter/test/test_interpreter.py
b/pypy/interpreter/test/test_interpreter.py
--- a/pypy/interpreter/test/test_interpreter.py
+++ b/pypy/interpreter/test/test_interpreter.py
@@ -379,6 +379,20 @@
assert X().f() == 42
"""
+ def test_kwonlyarg_required(self):
+ """
+ def f(*, a=5, b):
+ return (a, b)
+ assert f(b=10) == (5, 10)
+ assert f(a=7, b=12) == (7, 12)
+ raises(TypeError, f)
+ raises(TypeError, f, 1)
+ raises(TypeError, f, 1, 1)
+ raises(TypeError, f, a=1)
+ raises(TypeError, f, 1, a=1)
+ raises(TypeError, f, 1, b=1)
+ """
+
def test_extended_unpacking_short(self):
"""
class Seq:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit