Add type hints and keyword-only arguments for djblets.webapi.responses.

Review Request #12724 — Created Nov. 14, 2022 and submitted — Latest diff uploaded

Information

Djblets
release-3.x

Reviewers

The djblets.webapi.responses classes (WebAPIResponse,
WebAPIResponsePaginated, WebAPIResponseError,
WebAPIResponseFormError) are core to our API code. These convert
internal structured API response data to payloads for the client.

Although this code rarely needs to change, much of this code is very
old, in need of some love, and in need of unit testing.

To assist in some in-progress work on the API and code using the API,
this change adds type hints to this code, and changes constructors to
require keyword-only arguments (with deprecated compatibility with
positional arguments).

In the process, the documentation for these classes have been fleshed
out.

This did uncover some flaws in WebAPIResponsePaginated where various
methods would crash if queryset was None, or when passing obj to
the constructor. Both have been fixed.

Some unit tests have been added for construction, but many tests are
still lacking.

All unit tests pass.

No issues reported by mypy or pyright.

Commits

Files

    Loading...