Add framework for typing query arguments to methods.

Review Request #14339 — Created Feb. 10, 2025 and submitted

Information

RBTools
master

Reviewers

This change adds some machinery for rewriting query argument names so we
can more easily deal with API endpoints that use hyphens in parameters.

A couple new classes have been added for basic parameter lists for GET
operations on item and list resources, that include the built-in request
parameters that are supported for all resources.

I've also added additional TypedDicts for existing resource subclasses
which have special parameters for their GET operations. This makes it so
something like root.get_review_requests(branch=False) will pop up a
warning that the branch parameter must be str.

  • Ran unit tests.
  • Used a test script to verify that typing was correctly passed through
    for methods that take kwargs for query parameters.
Summary ID
Add framework for typing query arguments to methods.
This change adds some machinery for rewriting query argument names so we can more easily deal with API endpoints that use hyphens in parameters. A couple new classes have been added for basic parameter lists for GET operations on item and list resources, that include the built-in request parameters that are supported for all resources. I've also added additional TypedDicts for existing resource subclasses which have special parameters for their GET operations. This makes it so something like `root.get_review_requests(branch=False)` will pop up a warning that the `branch` parameter must be `str`. Testing Done: - Ran unit tests. - Used a test script to verify that typing was correctly passed through for methods that take kwargs for query parameters.
ccae3d5a8994a0556186a71f38655124406c67ba
Description From Last Updated

redefinition of unused 'Mapping' from line 13 Column: 5 Error code: F811

reviewbotreviewbot

Missing Version Added.

chipx86chipx86

Missing Version Added.

chipx86chipx86

These should be switched to keep sort order.

chipx86chipx86

Missing Version Added.

chipx86chipx86

We should use a Mapping here, so it's not typed as mutable.

chipx86chipx86

Should we take headers as Mapping?

chipx86chipx86

Missing Version Added.

chipx86chipx86

Is this because we transform query_args above? Rather than a cast, it might be more type-safe, if we define a …

chipx86chipx86

If we set the parent class to a Mapping, this will need to be changed too.

chipx86chipx86

Same with Mapping. Possibly others as well. I won't swamp the review with each instance.

chipx86chipx86
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
maubin
  1. Ship It!
  2. 
      
chipx86
  1. 
      
  2. rbtools/api/resource/base.py (Diff revision 2)
     
     
     
     
     
    Show all issues

    Missing Version Added.

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

    Missing Version Added.

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

    These should be switched to keep sort order.

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

    Missing Version Added.

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

    We should use a Mapping here, so it's not typed as mutable.

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

    Should we take headers as Mapping?

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

    Missing Version Added.

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

    Is this because we transform query_args above? Rather than a cast, it might be more type-safe, if we define a new variable of the correct type for the result, type it as needed, and set a default if query_args is empty. That'd be a bit more explicit.

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

    If we set the parent class to a Mapping, this will need to be changed too.

  11. Show all issues

    Same with Mapping. Possibly others as well. I won't swamp the review with each instance.

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