Skip to content

4.1.0

Choose a tag to compare

@github-actions github-actions released this 06 Nov 00:29
· 42 commits to main since this release
403603e

See Migration
for what to check when upgrading.

Changed

  • parse and parse_json now raise InvalidResponse for an empty response
    batch. They used to return an empty iterator and silently accept the invalid
    reply.
  • If a response has both result and error, and error is not null,
    parse now returns an Error. It used to return Ok(result=None) and drop
    the server's error. JSON-RPC 2.0 doesn't allow both, but JSON-RPC 1.0 style
    servers send "result": null with an error.
  • If a response has a result and a non-null error that isn't an object
    with code and message (for example a string, false or ""), parse
    now raises InvalidResponse. 4.0 returned Ok and ignored the error.
  • parse_json on JSON that isn't an object or array, such as "pong", used to
    say "Use parse_json on strings". It now says it expected an object.
  • parse given bytes now raises the same "Use parse_json on strings" error as
    a str.
  • notification sends tuple params as a list, the same as request does.
    The JSON output is unchanged, but the returned dict now holds a list.

Added

  • Malformed responses now raise InvalidResponse with a message that says what
    is wrong, for example missing 'id'. It subclasses KeyError and
    TypeError, which earlier versions raised, so existing except clauses
    still catch it.

Documentation

  • The parse docstring now says that a batch gives a one-pass lazy iterator,
    not a list.
  • New pages: an API reference generated from the docstrings, a migration
    guide, and one page per transport. New guides cover notifications, batches,
    ids, error handling, typing and threads.