Enhance typing for KeyValueForm.

Review Request #14437 — Created May 13, 2025 and submitted

Information

Djblets
release-6.x

Reviewers

This change makes it so KeyValueForm is typed as a generic, allowing us
to specify the type of the instance member which is operated on. The
default implementations of get and set assume a dict-like interface, so
I've additionally added some runtime-checkable protocols for those.

  • Ran unit tests.
  • Verified that type checkers were happy when creating KeyValueForm
    subclasses.
Summary ID
Enhance typing for KeyValueForm.
This change makes it so KeyValueForm is typed as a generic, allowing us to specify the type of the `instance` member which is operated on. The default implementations of get and set assume a dict-like interface, so I've additionally added some runtime-checkable protocols for those. Testing Done: - Ran unit tests. - Verified that type checkers were happy when creating KeyValueForm subclasses.
5198a036e8c4a39c7dc0e9ff6d5917f15106f6a1
Description From Last Updated

I think this can live in TYPE_CHECKING.

chipx86chipx86

This needs a Version Added and a Version Changed in __init__.

chipx86chipx86

Do we want parens in the returns? We've been doing without in this form.

chipx86chipx86

While here, we can move request into the function definition after *args.

chipx86chipx86

These should be swapped.

chipx86chipx86

Missing , optional.

chipx86chipx86
There are no open issues
maubin
  1. Ship It!
  2. 
      
chipx86
  1. 
      
  2. djblets/forms/forms/key_value_form.py (Diff revision 1)
     
     
    Show all issues

    I think this can live in TYPE_CHECKING.

    1. KeyValueForm inherits from Generic[_T]

  3. djblets/siteconfig/forms.py (Diff revision 1)
     
     
     
    Show all issues

    This needs a Version Added and a Version Changed in __init__.

    1. This has always been part of the kwargs, but I'll add a version changed blurb about the removal of the default.

  4. djblets/siteconfig/forms.py (Diff revision 1)
     
     
    Show all issues

    Do we want parens in the returns? We've been doing without in this form.

    1. Nope, just a copy/paste-o.

  5. 
      
david
david
chipx86
  1. 
      
  2. djblets/extensions/forms.py (Diff revision 3)
     
     
    Show all issues

    While here, we can move request into the function definition after *args.

  3. djblets/integrations/forms.py (Diff revision 3)
     
     
     
    Show all issues

    These should be swapped.

  4. djblets/siteconfig/forms.py (Diff revision 3)
     
     
    Show all issues

    Missing , optional.

  5. 
      
david
chipx86
  1. Ship It!
  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to release-6.x (90d53c8)
Loading...