Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit ebd7f16

Browse files
committed
rpc: method introspection: add repr
Signed-off-by: Florian Scherf <f.scherf@pengutronix.de>
1 parent d1a544b commit ebd7f16

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

aiohttp_json_rpc/rpc.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ def __init__(self, method):
6464
if i not in self.CREDENTIAL_KEYS + ['self']
6565
]
6666

67+
# gen repr string
68+
args = []
69+
70+
for i, v in enumerate(self.args[::-1]):
71+
if self.defaults and not i >= len(self.defaults):
72+
args.append('{}={}'.format(v, repr(self.defaults[i])))
73+
74+
else:
75+
args.append(v)
76+
77+
args = [
78+
*[i for i in self.CREDENTIAL_KEYS if i in self.argspec.args],
79+
*args[::-1],
80+
]
81+
82+
self._repr_str = 'JsonRpcMethod({}({}))'.format(
83+
self.method.__name__,
84+
', '.join(args),
85+
)
86+
87+
def __repr__(self):
88+
return self._repr_str
89+
6790
async def __call__(self, http_request, rpc, msg):
6891
params = msg.data['params']
6992
method_params = dict()

tests/test_method_args.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,4 @@ async def test_introspection_of_unsupported_function_types(rpc_context):
168168
)
169169

170170
assert not rpc_context.rpc.methods['min'].introspected
171+
assert rpc_context.rpc.methods['min'].argspec.args == ['request']

0 commit comments

Comments
 (0)