Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ work in 5.x but give a `DeprecationWarning`, and will be removed in 6.0.

### Fixes

- `@method(name="")` now registers the empty name. It used to ignore that
name and register the function's name instead.
- The development server, `serve()`, dropped every connection without a
response when `sys.stderr` was `None`. That's the case in a PyInstaller app
built with `--noconsole` (#269). It now logs requests through the logging
Expand Down
2 changes: 1 addition & 1 deletion jsonrpcserver/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def add(a: int, b: int) -> Result:
"""

def decorator(func: F) -> F:
method_name = name or func.__name__
method_name = func.__name__ if name is None else name
if method_name.startswith("rpc."):
warnings.warn(
f"Method names starting with 'rpc.' are reserved by the JSON-RPC spec "
Expand Down
16 changes: 16 additions & 0 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Test methods.py"""

import pytest

from jsonrpcserver import Result, Success, dispatch
from jsonrpcserver.methods import global_methods, method

# pylint: disable=missing-function-docstring
Expand All @@ -19,3 +22,16 @@ def name() -> None:
pass

assert callable(global_methods["new_name"])


def test_decorator_empty_name(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setitem(global_methods, "", lambda: Success("previous"))

@method(name="")
def empty_name() -> Result:
return Success("pong")

assert dispatch('{"jsonrpc": "2.0", "method": "", "id": 1}') == (
'{"jsonrpc": "2.0", "result": "pong", "id": 1}'
)
assert global_methods[""] is empty_name