• 
      

    Improve typing for LocalSite and LocalSiteManager.

    Review Request #14954 — Created March 24, 2026 and submitted

    Information

    Review Board
    release-7.1.x

    Reviewers

    This adds typing throughout LocalSite and LocalSiteManager, fleshing
    out arguments, return types, field relations, and the Local Site
    statistics dictionaries.

    It also modernizes some of the documentation, which was pretty out of
    date, and deprecates some positional arguments.

    Unit tests pass.

    Summary ID
    Improve typing for LocalSite and LocalSiteManager.
    This adds typing throughout `LocalSite` and `LocalSiteManager`, fleshing out arguments, return types, field relations, and the Local Site statistics dictionaries. It also modernizes some of the documentation, which was pretty out of date, and deprecates some positional arguments.
    7044a62cf20cdc73e9bef1b587fae3f34d669ee4
    Description From Last Updated

    Preexisting typo: LocalSit -> LocalSite

    david david

    ValueError is probably more correct.

    david david

    ValueError is probably more correct.

    david david

    This string is missing f-prefixes

    david david

    This docstring doesn't list any exceptions. If we keep the assert it should have AssertionError, if we change to raise_invalid_type …

    david david

    If we want runtime checking that won't be stripped with -O, instead of an assert it might be nice to …

    david david

    SyntaxError: expected ':' Column: 48 Error code: E999

    reviewbot reviewbot

    This and below will need to be changed to 8.0 now.

    maubin maubin

    This and the docstring below can be bumped to RB 10.0 too.

    maubin maubin

    I know we have reviewboard.accounts.models.User, should we be using that instead of django.contrib.auth.models.User?

    maubin maubin

    Same comments above.

    maubin maubin
    david
    1. 
        
    2. reviewboard/site/managers.py (Diff revision 1)
       
       
      Show all issues

      Preexisting typo: LocalSit -> LocalSite

    3. reviewboard/site/managers.py (Diff revision 1)
       
       
      Show all issues

      ValueError is probably more correct.

    4. reviewboard/site/managers.py (Diff revision 1)
       
       
      Show all issues

      ValueError is probably more correct.

    5. reviewboard/site/managers.py (Diff revision 1)
       
       
       
      Show all issues

      This string is missing f-prefixes

    6. reviewboard/site/managers.py (Diff revision 1)
       
       
      Show all issues

      This docstring doesn't list any exceptions. If we keep the assert it should have AssertionError, if we change to raise_invalid_type (see next comment) it should be ValueError

    7. reviewboard/site/managers.py (Diff revision 1)
       
       
      Show all issues

      If we want runtime checking that won't be stripped with -O, instead of an assert it might be nice to do:

      if isinstance(local_site_or_id, self.model):
          ...
      elif isinstance(local_site_or_id, int):
          ...
      else:
          raise_invalid_type(...)
      
      1. This is one of those things we shouldn't ever have to come across in production, though I agree it's better safe than sorry.

        (FWIW, we don't ship Review Board in optimized mode, but we do ship Power Pack.)

        All that said, raise_invalid_type() becomes a mess here, because we're not checking against LocalSite, we're checking against self.model, and it doesn't know the difference. To make it do what it should, we'd need to check against LocalSite, which is technically wrong and logistically annoying, because then the manager has to import the model using the manager.

        I want to leave this alone for now, given the constraints here.

      2. To be clear on that, if we do:

                if isinstance(local_site_or_id, self.model):
                    local_site_id = local_site_or_id.pk
                elif isinstance(local_site_or_id, int):
                    local_site_id = local_site_or_id
                else:
                    raise_invalid_type(
                        local_site_or_id,
                        'local_site_or_id must be a LocalSite instance or int',
                    )
        

        Then raise_invalid_type() errors at type checking time because we haven't exhausted all available conditions (it says it's not compatible with Never), even though the generic for the manager is typed as a LocalSite.

      3. ok

    8. 
        
    chipx86
    Review request changed
    Change Summary:
    • Switched some AssertionErrors to ValueErrors.
    • Fixed a typo in a docstring.
    • Added missing f-prefixes for a string.
    Commits:
    Summary ID
    Improve typing for LocalSite and LocalSiteManager.
    This adds typing throughout `LocalSite` and `LocalSiteManager`, fleshing out arguments, return types, field relations, and the Local Site statistics dictionaries. It also modernizes some of the documentation, which was pretty out of date, and deprecates some positional arguments.
    4f5733630086b8f6c66bc8bcb7b426bb2d805e3a
    Improve typing for LocalSite and LocalSiteManager.
    This adds typing throughout `LocalSite` and `LocalSiteManager`, fleshing out arguments, return types, field relations, and the Local Site statistics dictionaries. It also modernizes some of the documentation, which was pretty out of date, and deprecates some positional arguments.
    e137b84926d5740056cd0f1f89e1723e54f01103

    Checks run (1 failed, 1 succeeded)

    flake8 failed.
    JSHint passed.

    flake8

    chipx86
    david
    1. Ship It!
    2. 
        
    maubin
    1. 
        
    2. reviewboard/site/managers.py (Diff revision 3)
       
       
      Show all issues

      This and below will need to be changed to 8.0 now.

    3. reviewboard/site/managers.py (Diff revision 3)
       
       
       
      Show all issues

      This and the docstring below can be bumped to RB 10.0 too.

    4. reviewboard/site/models.py (Diff revision 3)
       
       
      Show all issues

      I know we have reviewboard.accounts.models.User, should we be using that instead of django.contrib.auth.models.User?

      1. It's a bit messy. We'd have to explicitly use django.contrib.auth.models.User for the fields, even though we could avoid it for the types (mostly). Since the Django one is at least a subset of the Review Board one, and we are guaranteed at least that type in most cases, it's probably the right choice right now so we don't have typing errors wherever this is called. But there are places where we probably do want to cast to, say, a RBUser when we're accessing special attributes/methods on the user.

        Basically, it's easier and safer to use what we have here for these cases and in this file than to convert.

      2. I see.

    5. reviewboard/site/models.py (Diff revision 3)
       
       
       
       
       
       
      Show all issues

      Same comments above.

    6. 
        
    chipx86
    maubin
    1. 
        
    2. 
        
    david
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-7.1.x (c162da0)