Add typing and missing documentation to review request fields.

Review Request #14300 — Created Jan. 24, 2025 and updated

Information

Review Board
release-7.1.x

Reviewers

The review request fields codebase is pretty crucial to Review Board,
and one of the primary extension interfaces that companies tend to
use and specialize.

In an effort to modernize fields and help reason about them in other
code that needs to interact with them, this change adds typing
throughout the fields codebases.

Fields are now generics, storing the type of data that can be
represented when loading and saving values.

All rendering functions now have return types of SafeString.

The base functions rendering or serializing change description state
work with Any as the type. This is because, while we have a
somewhat-standard format most fields use to record state in
ChangeDescription.fields_changed, this is entirely at the whim of the
implementation. As such, it's up to the field class to narrow the type
as needed and perform any checks and parsing required.

All unit tests passed.

Tested all the field types on a review request, and a wide variety of
change description renderings.

Summary ID
Add typing and missing documentation to review request fields.
The review request fields codebase is pretty crucial to Review Board, and one of the primary extension interfaces that companies tend to use and specialize. In an effort to modernize fields and help reason about them in other code that needs to interact with them, this change adds typing throughout the fields codebases. Fields are now generics, storing the type of data that can be represented when loading and saving values. All rendering functions now have return types of `SafeString`. The base functions rendering or serializing change description state work with `Any` as the type. This is because, while we have a somewhat-standard format most fields use to record state in `ChangeDescription.fields_changed`, this is entirely at the whim of the implementation. As such, it's up to the field class to narrow the type as needed and perform any checks and parsing required. In the process, several typing issues, bad assumptions, and incorrect documentation were found and fixed.
61ee33db0bfe3bc3afbab334122e9edb6a2db3b9
Description From Last Updated

Could say the User type here instead of object. And now that we've switched to importing from reviewboard.accounts.models.User, is that …

maubinmaubin

Group instead of object.

maubinmaubin

User instead of object.

maubinmaubin

You missed a super() here.

daviddavid

Forgot to add the type here.

maubinmaubin

And here.

maubinmaubin

Missing types on some of the attributes here.

maubinmaubin

'djblets.util.typing.JSONDict' imported but unused Column: 5 Error code: F401

reviewbotreviewbot
There are no open issues
david
  1. 
      
  2. reviewboard/reviews/fields.py (Diff revision 1)
     
     
    Show all issues

    You missed a super() here.

  3. 
      
maubin
  1. 
      
  2. reviewboard/reviews/builtin_fields.py (Diff revision 1)
     
     
     
     
     
    Show all issues

    Could say the User type here instead of object. And now that we've switched to importing from reviewboard.accounts.models.User, is that the value that we should use moving forward in docstrings instead of django.contrib.auth.models.User?

  3. reviewboard/reviews/builtin_fields.py (Diff revision 1)
     
     
    Show all issues

    Group instead of object.

  4. reviewboard/reviews/builtin_fields.py (Diff revision 1)
     
     
    Show all issues

    User instead of object.

  5. reviewboard/reviews/fields.py (Diff revision 1)
     
     
    Show all issues

    Forgot to add the type here.

  6. reviewboard/reviews/fields.py (Diff revision 1)
     
     
     
     
     
     
    Show all issues

    And here.

  7. reviewboard/reviews/fields.py (Diff revision 1)
     
     
    Show all issues

    Missing types on some of the attributes here.

    1. These are setting values defined in the base class.

  8. 
      
chipx86
Review request changed
Change Summary:
  • Modernized another super() call.
  • Fixed docstrings to reference specific object types where possible.
  • Added typing to some default_value attributes when introduced in a class.
Commits:
Summary ID
Add typing and missing documentation to review request fields.
The review request fields codebase is pretty crucial to Review Board, and one of the primary extension interfaces that companies tend to use and specialize. In an effort to modernize fields and help reason about them in other code that needs to interact with them, this change adds typing throughout the fields codebases. Fields are now generics, storing the type of data that can be represented when loading and saving values. All rendering functions now have return types of `SafeString`. The base functions rendering or serializing change description state work with `Any` as the type. This is because, while we have a somewhat-standard format most fields use to record state in `ChangeDescription.fields_changed`, this is entirely at the whim of the implementation. As such, it's up to the field class to narrow the type as needed and perform any checks and parsing required. In the process, several typing issues, bad assumptions, and incorrect documentation were found and fixed.
03186ee8fef188fc54d74ee130fb1a55ac448dfb
Add typing and missing documentation to review request fields.
The review request fields codebase is pretty crucial to Review Board, and one of the primary extension interfaces that companies tend to use and specialize. In an effort to modernize fields and help reason about them in other code that needs to interact with them, this change adds typing throughout the fields codebases. Fields are now generics, storing the type of data that can be represented when loading and saving values. All rendering functions now have return types of `SafeString`. The base functions rendering or serializing change description state work with `Any` as the type. This is because, while we have a somewhat-standard format most fields use to record state in `ChangeDescription.fields_changed`, this is entirely at the whim of the implementation. As such, it's up to the field class to narrow the type as needed and perform any checks and parsing required. In the process, several typing issues, bad assumptions, and incorrect documentation were found and fixed.
e29c78d9189ea424f0be403220261e50480762d6
Diff:

Revision 2 (+1818 -686)

Show changes

reviewboard/reviews/builtin_fields.py
reviewboard/reviews/fields.py

Checks run (1 failed, 1 succeeded)

flake8 failed.
JSHint passed.

flake8

chipx86
Review request changed
Change Summary:

Removed an unused import.

Commits:
Summary ID
Add typing and missing documentation to review request fields.
The review request fields codebase is pretty crucial to Review Board, and one of the primary extension interfaces that companies tend to use and specialize. In an effort to modernize fields and help reason about them in other code that needs to interact with them, this change adds typing throughout the fields codebases. Fields are now generics, storing the type of data that can be represented when loading and saving values. All rendering functions now have return types of `SafeString`. The base functions rendering or serializing change description state work with `Any` as the type. This is because, while we have a somewhat-standard format most fields use to record state in `ChangeDescription.fields_changed`, this is entirely at the whim of the implementation. As such, it's up to the field class to narrow the type as needed and perform any checks and parsing required. In the process, several typing issues, bad assumptions, and incorrect documentation were found and fixed.
e29c78d9189ea424f0be403220261e50480762d6
Add typing and missing documentation to review request fields.
The review request fields codebase is pretty crucial to Review Board, and one of the primary extension interfaces that companies tend to use and specialize. In an effort to modernize fields and help reason about them in other code that needs to interact with them, this change adds typing throughout the fields codebases. Fields are now generics, storing the type of data that can be represented when loading and saving values. All rendering functions now have return types of `SafeString`. The base functions rendering or serializing change description state work with `Any` as the type. This is because, while we have a somewhat-standard format most fields use to record state in `ChangeDescription.fields_changed`, this is entirely at the whim of the implementation. As such, it's up to the field class to narrow the type as needed and perform any checks and parsing required. In the process, several typing issues, bad assumptions, and incorrect documentation were found and fixed.
61ee33db0bfe3bc3afbab334122e9edb6a2db3b9
Diff:

Revision 3 (+1818 -686)

Show changes

reviewboard/reviews/builtin_fields.py
reviewboard/reviews/fields.py

Checks run (2 succeeded)

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