Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit empty "params" in requests #9

Merged
merged 1 commit into from Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion jsonrpc_base/jsonrpc.py
Expand Up @@ -193,7 +193,7 @@ def response_id(self):
def serialize(self):
"""Generate the raw JSON message to be sent to the server"""
data = {'jsonrpc': '2.0', 'method': self.method}
if self.params is not None:
if self.params:
data['params'] = self.params
if self.msg_id is not None:
data['id'] = self.msg_id
Expand Down
9 changes: 7 additions & 2 deletions tests.py
Expand Up @@ -62,11 +62,16 @@ def test_dumps(server):
)
# test empty args dict
assertSameJSON(
'''{"params": {}, "jsonrpc": "2.0", "method": "my_method_name", "id":
1}''',
'''{"jsonrpc": "2.0", "method": "my_method_name", "id": 1}''',
jsonrpc_base.Request(
'my_method_name', params={}, msg_id=1).serialize()
)
# test empty args array
assertSameJSON(
'''{"jsonrpc": "2.0", "method": "my_method_name", "id": 1}''',
jsonrpc_base.Request(
'my_method_name', params=[], msg_id=1).serialize()
)
# test keyword args
assertSameJSON(
'''{"params": {"foo": "bar"}, "jsonrpc": "2.0", "method":
Expand Down