• 
      

    Improve typing for LocalSite and LocalSiteManager.

    Review Request #14954 — Created March 23, 2026 and updated

    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.
    7c754e38934bf786c3f3b129ca7744a96efaa7fd
    Description From Last Updated

    Preexisting typo: LocalSit -> LocalSite

    daviddavid

    ValueError is probably more correct.

    daviddavid

    ValueError is probably more correct.

    daviddavid

    This string is missing f-prefixes

    daviddavid

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

    daviddavid

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

    daviddavid

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

    reviewbotreviewbot
    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
    Review request changed
    Change Summary:

    Added a mising colon.

    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.
    e137b84926d5740056cd0f1f89e1723e54f01103
    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.
    7c754e38934bf786c3f3b129ca7744a96efaa7fd

    Checks run (2 succeeded)

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