Add stubs for API resources and implement root stubs for existing subclasses.

Review Request #14257 — Created Dec. 4, 2024 and updated

Information

RBTools
master

Reviewers

This change adds a new @api_stub decorator that we can use to define
stubs within resource implementations. These stubs provide type hints
and documentation for any methods which will be dynamically generated.

We have only a subset of subclasses for resources. For the ones we do
currently have, this adds stubs to the root resource for the methods
that are automatically generated from URI-templates. With this, if one's
editor is so configured, a developer can write
api_root.get_review_request( and the editor will auto-complete the
review_request_id parameter and indicate that the resulting value is a
ReviewRequestItemResource.

  • Ran unit tests.
  • Verified that stub methods were correctly replaced, and that doing
    things like help(api_root.get_review_request) showed the correct
    documentation and annotations.
Summary ID
Add stub functionality for base resources and implement review request.
This change adds support for `@api_stub` for the base resource class, used for "special" links (create/update/delete/etc) as well as for any resource-specific links. This also adds a new decorator, `@request_method_returns`, which works like `@request_method`, but can plumb through a specific return type. This has been used to make `ResourceLinkField` generic, so that calls to a `ResourceLinkField.get()` method can specify their return type as a specific resource subclass. Stubs for common special methods have been added to Resource, ItemResource, and ListResource. This change also adds resource-specific stubs to ReviewRequestItemResource, for those links where we have existing resource classes to reference. I've also added type hints for the review request attributes. Testing Done: - Ran unit tests. - Smoke tested rbt commands. - Ran a test script with debug logging to see that the stub debug info looked as expected.
ef110b6cafd99df95b5a1e76c378ab2f7debad28
Checks run (2 succeeded)
flake8 passed.
JSHint passed.