Add support for using keyword arguments with a named struct in an RPC
This commit is contained in:
@@ -2050,7 +2050,7 @@ cdef class _DynamicCapabilityClient:
|
|||||||
return _find_field_order(params.struct)
|
return _find_field_order(params.struct)
|
||||||
|
|
||||||
cdef _set_fields(self, Request * request, name, args, kwargs):
|
cdef _set_fields(self, Request * request, name, args, kwargs):
|
||||||
if args is not None:
|
if args is not None and len(args) > 0:
|
||||||
arg_names = self._find_method_args(name)
|
arg_names = self._find_method_args(name)
|
||||||
if len(args) > len(arg_names):
|
if len(args) > len(arg_names):
|
||||||
raise KjException('Too many arguments passed to `%s`. Expected %d and got %d' % (name, len(arg_names), len(args)))
|
raise KjException('Too many arguments passed to `%s`. Expected %d and got %d' % (name, len(arg_names), len(args)))
|
||||||
|
|||||||
@@ -81,3 +81,11 @@ interface TestTailCaller {
|
|||||||
interface TestPassedCap {
|
interface TestPassedCap {
|
||||||
foo @0 (cap :TestInterface) -> (x: Text);
|
foo @0 (cap :TestInterface) -> (x: Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface TestStructArg {
|
||||||
|
bar @0 BarParams -> (c: Text);
|
||||||
|
}
|
||||||
|
struct BarParams {
|
||||||
|
a @0 :Text;
|
||||||
|
b @1 :Int32;
|
||||||
|
}
|
||||||
|
|||||||
@@ -358,3 +358,15 @@ def test_null_cap():
|
|||||||
|
|
||||||
with pytest.raises(capnp.KjException):
|
with pytest.raises(capnp.KjException):
|
||||||
client.foo().wait()
|
client.foo().wait()
|
||||||
|
|
||||||
|
|
||||||
|
class TestStructArg(capability.TestStructArg.Server):
|
||||||
|
def bar(self, a, b, **kwargs):
|
||||||
|
return a + str(b)
|
||||||
|
|
||||||
|
|
||||||
|
def test_struct_args():
|
||||||
|
client = capability.TestStructArg._new_client(TestStructArg())
|
||||||
|
assert client.bar(a='test', b=1).wait().c == 'test1'
|
||||||
|
with pytest.raises(capnp.KjException):
|
||||||
|
assert client.bar('test', 1).wait().c == 'test1'
|
||||||
|
|||||||
Reference in New Issue
Block a user