From 7fed19a9a81ec9c539db98bec4e3da0ab0c05265 Mon Sep 17 00:00:00 2001 From: retke Date: Tue, 19 Feb 2019 22:01:10 +0100 Subject: [PATCH] Remove the lenght of arguments conditions Edited-by: Florian Scherf - pep8 fix - added test --- aiohttp_json_rpc/rpc.py | 2 +- tests/test_method_args.py | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/aiohttp_json_rpc/rpc.py b/aiohttp_json_rpc/rpc.py index 1b4d978..0f2913a 100644 --- a/aiohttp_json_rpc/rpc.py +++ b/aiohttp_json_rpc/rpc.py @@ -51,7 +51,7 @@ def __init__(self, method): # required args self.required_args = copy(self.args) - if not (len(self.args) == 1 and self.defaults is None): + if self.defaults: self.required_args = [ i for i in self.args[:-len(self.defaults or ())] if i not in self.CREDENTIAL_KEYS diff --git a/tests/test_method_args.py b/tests/test_method_args.py index 7d4f2ea..354bd22 100644 --- a/tests/test_method_args.py +++ b/tests/test_method_args.py @@ -7,6 +7,9 @@ async def test_args(rpc_context): async def method1(request, a): return a + async def method1_1(request, a, b): + return [a, b] + async def method2(request, a, b, c=1): return [a, b, c] @@ -44,6 +47,7 @@ async def method4(self): # setup rpc and client rpc_context.rpc.add_methods( ('', method1), + ('', method1_1), ('', method2), ('', method3), ('', method4), @@ -54,6 +58,7 @@ async def method4(self): # simple coroutine based methods assert await client.call('method1', 1) == 1 + assert await client.call('method1_1', [1, 2]) == [1, 2] assert await client.call('method2', [1, 2]) == [1, 2, 1] assert await client.call('method2', [1, 2, 3]) == [1, 2, 3]