Skip to content

Docstrings for every public name, and clearer messages for two mistakes - #305

Merged
bensynapse merged 1 commit into
mainfrom
docs/docstrings-and-hints
Oct 6, 2026
Merged

bensynapse merged 1 commit into
mainfrom
docs/docstrings-and-hints

Conversation

@bensynapse

Copy link
Copy Markdown
Owner

This is the code half of the docs review from 2026-10-06. The docs half
follows in a second pull request, which builds the API reference from these
docstrings.

Docstrings. Every name in __all__ now has a Google-style docstring with
its arguments, return value, exceptions and warnings. Most also have an
example, which tests/test_docstrings.py runs. Success, Error and the
three async_dispatch* functions had no docstring at all. The public names in
jsonrpcserver.response, jsonrpcserver.result, jsonrpcserver.codes,
NODATA and global_methods have one too. Some module docstrings were wrong:
one named dispatch_to_responses, which doesn't exist, and one showed a method
returning a plain value. Those are fixed. No signatures changed.

A clearer log line for a plain return value. A 4.x method such as
return "pong" gives a bare Internal error on 5.x. On 5.0.9 the client at
least saw "did not return a valid Result" in data. 5.0.10 rightly removed
that, so the only clue left was a traceback that pointed into jsonrpcserver.
Now the log says:

Method 'ping' returned 'pong', which is not a Result, so the client got an Internal error. Return Success(value) or Error(code, message). Since 5.0 a plain return value is not enough: https://bensynapse.github.io/jsonrpcserver/migration/

The response is unchanged. With debug=True, its data keeps the old text
and adds the same hint. The new exception is a subclass of AssertionError,
so nothing that caught the old one breaks.

serve() says where it's listening. With the default host it warns that it
accepts connections on every network interface. It also says how to limit it
to localhost. The line is logged on jsonrpcserver.server, as before. When
logging isn't configured it also goes to stderr, because the INFO log line went
nowhere and the server printed nothing at all. It skips stderr when it's
None, so the PyInstaller fix from #269 still holds.

Checks run locally on Python 3.13: pytest with 100% coverage (251 tests), ruff
check, ruff format, mypy and pyright.

The docs site will get an API reference built from the docstrings. So every
public function and class now has a full one, with arguments, return values,
exceptions, warnings and a tested example. Success, Error and the three async
dispatch functions had none. The module docstrings that named a function that
doesn't exist, or showed a method returning a plain value, are fixed.

A method that returns a plain value, as 4.x methods did, now logs one line.
It says to return Success(value) or Error(code, message), and links to the
migration guide. Before, the log showed a traceback into jsonrpcserver and the
client got a bare Internal error, so there was nothing to go on. The response
is the same as before. With debug=True its data has the same hint.

serve() now says where it's listening when it starts. With the default host it
says that it accepts connections on every network interface. The line goes to
the jsonrpcserver.server logger, and to stderr when logging isn't configured.
It still writes nothing when sys.stderr is None (#269).

tests/test_docstrings.py runs the docstring examples and checks that every
name in __all__ has a docstring.
@bensynapse
bensynapse merged commit a279e3a into main Oct 6, 2026
12 checks passed
@bensynapse
bensynapse deleted the docs/docstrings-and-hints branch October 6, 2026 02:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant