• 
      

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

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

    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.
    a0fae2d0e384e6ac5209aaebc2380a504cdde153
    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

    Missing Returns.

    chipx86chipx86

    This and the other new methods and globls are missing Version Added.

    chipx86chipx86
    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
    maubin
    1. Ship It!
    2. 
        
    chipx86
    1. 
        
    2. rbtools/api/resource/base.py (Diff revision 2)
       
       
       
       
       
       
       
      Show all issues

      Missing Returns.

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

      This and the other new methods and globls are missing Version Added.

    4. rbtools/api/resource/root.py (Diff revision 2)
       
       

      I didn't even realize we could use the walrus operator now. Time has flown. I'm fine with this, but do we want to establish any code policy around when and where to use it?

      1. I don't know that we need to? When it's useful it's pretty straightforward.

    5. 
        
    david
    david
    chipx86
    1. Ship It!
    2. 
        
    david
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to master (7c14ae7)