mbr / tinyrpc

A compact, modular transport and protocol agnostic RPC library. Does jsonrpc v2.
https://tinyrpc.readthedocs.org
MIT License
156 stars 53 forks source link

Request default kwargs don't work with dispatch #86

Closed ggggggggg closed 3 years ago

ggggggggg commented 4 years ago
from tinyrpc.protocols.jsonrpc import JSONRPCProtocol
from tinyrpc import BadRequestError
from tinyrpc.dispatch import RPCDispatcher

dispatch = RPCDispatcher()

dispatch.add_method(lambda a,b: a+b, "add")
dispatch.add_method(lambda s: s, "echo")

rpc = JSONRPCProtocol()

request = rpc.create_request("add", args=[1,2]) 
print(request.serialize())

response = dispatch.dispatch(request)

print(response.serialize())

dispatch.validator=None
response2 = dispatch.dispatch(request)
print(response2.serialize())

## -- End pasted text --
b'{"jsonrpc": "2.0", "method": "add", "params": [1, 2], "id": 1}'
b'{"jsonrpc": "2.0", "id": 1, "error": {"message": "Invalid params", "code": -32602}}'
b'{"jsonrpc": "2.0", "id": 1, "error": {"message": "<lambda>() argument after ** must be a mapping, not NoneType", "code": -32000}}'

I expected both the 2nd and the 3rd prints to show a succesful method call. It seems like the default request value for kwargs must be None which invalid for use with **. Would {} be a better default?