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 stubs for API resources and implement root stubs for existing subclasses.
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`. Testing Done: - 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.
ba14a7a69e50537935904a89b0b564dea9cb337b
Description From Last Updated

Where are the function definitions for is_api_stub() and replace_api_stub()?

maubinmaubin

I think there's an extra space before the ending apostrophe?

maubinmaubin
maubin
  1. 
      
  2. rbtools/api/resource/base.py (Diff revision 1)
     
     
     
    Show all issues

    Where are the function definitions for is_api_stub() and replace_api_stub()?

    1. Huh, for some reason the posted diff was... not for this change. Fixed it.

  3. rbtools/api/resource/base.py (Diff revision 1)
     
     
    Show all issues

    I think there's an extra space before the ending apostrophe?

  4. 
      
david
Review request changed
Commits:
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
Add stubs for API resources and implement root stubs for existing subclasses.
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`. Testing Done: - 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.
ba14a7a69e50537935904a89b0b564dea9cb337b

Checks run (2 succeeded)

flake8 passed.
JSHint passed.
maubin
  1. Ship It!
  2.