From 130bb231d84e12836a90b1ab2971e9182b4d791a Mon Sep 17 00:00:00 2001 From: Emily Mills Date: Tue, 16 Mar 2021 12:52:35 -0500 Subject: [PATCH] Revert "Spec compliance: handle top-level mappings in function calls" This reverts commit 52b3cb9a6ea7574f145b5d33f636538e91673824. I'm not sure where this decision was originally made, but this logic is incorrect and unnecessary. Because we always load our parameters from *args, or **kwargs, we'll always pass either a tuple or dict, which means it'll always be a structured type per the spec. --- jsonrpc_base/jsonrpc.py | 8 -------- tests.py | 14 +++++++++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/jsonrpc_base/jsonrpc.py b/jsonrpc_base/jsonrpc.py index 7ed766b..7c7e587 100644 --- a/jsonrpc_base/jsonrpc.py +++ b/jsonrpc_base/jsonrpc.py @@ -1,4 +1,3 @@ -import collections import inspect import json import logging @@ -135,13 +134,6 @@ def __request(self, method_name, args=None, kwargs=None): raise ProtocolError( 'JSON-RPC spec forbids mixing arguments and keyword arguments') - # from the specs: - # "If resent, parameters for the rpc call MUST be provided as a - # Structured value. Either by-position through an Array or by-name - # through an Object." - if len(args) == 1 and isinstance(args[0], collections.abc.Mapping): - args = dict(args[0]) - return self.send_message(Request(method_name, args or kwargs, msg_id)) def __register(self, method_name, callback): diff --git a/tests.py b/tests.py index 4b0b8fb..26a7a05 100644 --- a/tests.py +++ b/tests.py @@ -229,7 +229,7 @@ def handler2(message): # rpc call with a mapping type def handler3(message): - assert message.params == {'foo': 'bar'} + assert message.params == [{'foo': 'bar'}] return { "jsonrpc": "2.0", "result": None, @@ -239,6 +239,18 @@ def handler3(message): server._handler = handler3 server.foobar({'foo': 'bar'}) + # rpc call with direct dict params + def handler3(message): + assert message.params == {'foo': 'bar'} + return { + "jsonrpc": "2.0", + "result": None, + "id": 1, + } + + server._handler = handler3 + server.foobar(**{'foo': 'bar'}) + def test_notification(server): # Verify that we ignore the server response