Skip to content

Commit

Permalink
Revert "Spec compliance: handle top-level mappings in function calls" (
Browse files Browse the repository at this point in the history
…#6)

This reverts commit 52b3cb9.

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.
  • Loading branch information
emlove authored Mar 16, 2021
1 parent 2abe2a7 commit 8e20494
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
8 changes: 0 additions & 8 deletions jsonrpc_base/jsonrpc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
import inspect
import json
import logging
Expand Down Expand Up @@ -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):
Expand Down
14 changes: 13 additions & 1 deletion tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 8e20494

Please sign in to comment.