Modernize the rest of chunk and opcode generators and differ base.

Review Request #14503 — Created July 11, 2025 and updated

Information

Review Board
master

Reviewers

This change finishes up modernization of the chunk_generator,
differ, and opcode_generator files in the diffviewer. For the most
part this just involves fixing up docstrings and adding type hints.

The one functional change in here is a fix for a subtle bug that I
discovered when working through this: when computing headers, we were
subtracting 1 from the end line numbers of the chunk twice: once in
_new_chunk, and once in _get_interesting_headers. This meant we'd
stop iterating one line too soon. We obviously didn't notice any bugs in
practice, but it's possible that it was affecting the header
computation, especially for chunks that are only a single line.

  • Ran unit tests.
  • Smoke tested a bunch of diffs.
Summary ID
Modernize the rest of chunk and opcode generators and differ base.
This change finishes up modernization of the `chunk_generator`, `differ`, and `opcode_generator` files in the diffviewer. For the most part this just involves fixing up docstrings and adding type hints. The one functional change in here is a fix for a subtle bug that I discovered when working through this: when computing headers, we were subtracting 1 from the end line numbers of the chunk twice: once in `_new_chunk`, and once in `_get_interesting_headers`. This meant we'd stop iterating one line too soon. We obviously didn't notice any bugs in practice, but it's possible that it was affecting the header computation, especially for chunks that are only a single line. Testing Done: - Ran unit tests. - Smoke tested a bunch of diffs.
zwkyoovslsqxvknqzpzmtqmpummrntmn
Description From Last Updated

Let's make <div> a code literal.

chipx86chipx86

Might be a nice time to make these keyword-only.

chipx86chipx86

And here.

chipx86chipx86

Let's use str(). It's faster than an f-string that just turns into a str().

chipx86chipx86

This can now use the {..., **...} syntax.

chipx86chipx86

Mising a period (old bug).

chipx86chipx86

We might as well just append [1], since we're not using the variable.

chipx86chipx86

Raises comes after Returns.

chipx86chipx86

This needs to be the full class path.

chipx86chipx86

Not that anyone should hit this, but we might as well localize it.

chipx86chipx86

This can be simplified to: self.groups = groups or []

chipx86chipx86

Looks like there's an off-by-one alignment issue here.

chipx86chipx86

We can move the r_move_range = None to the else to avoid double-setting the variable.

chipx86chipx86

And this changed to keyword only args.

maubinmaubin

Why can't we just give imeta a type of only dict[str, Any], since we always assert it to be non-None.

maubinmaubin
chipx86
  1. Good cleanup. Most of this is just small cleanups/nits.

  2. Show all issues

    Let's make <div> a code literal.

  3. reviewboard/diffviewer/chunk_generator.py (Diff revision 1)
     
     
     
     
     
    Show all issues

    Might be a nice time to make these keyword-only.

  4. reviewboard/diffviewer/chunk_generator.py (Diff revision 1)
     
     
     
    Show all issues

    And here.

  5. Show all issues

    Let's use str(). It's faster than an f-string that just turns into a str().

  6. reviewboard/diffviewer/chunk_generator.py (Diff revision 1)
     
     
     
     
    Show all issues

    This can now use the {..., **...} syntax.

  7. reviewboard/diffviewer/differ.py (Diff revision 1)
     
     
    Show all issues

    Mising a period (old bug).

  8. reviewboard/diffviewer/differ.py (Diff revision 1)
     
     
    Show all issues

    We might as well just append [1], since we're not using the variable.

  9. reviewboard/diffviewer/differ.py (Diff revision 1)
     
     
     
     
     
    Show all issues

    Raises comes after Returns.

  10. reviewboard/diffviewer/differ.py (Diff revision 1)
     
     
    Show all issues

    This needs to be the full class path.

  11. reviewboard/diffviewer/differ.py (Diff revision 1)
     
     
     
     
    Show all issues

    Not that anyone should hit this, but we might as well localize it.

  12. reviewboard/diffviewer/opcode_generator.py (Diff revision 1)
     
     
     
     
     
    Show all issues

    This can be simplified to:

    self.groups = groups or []
    
  13. reviewboard/diffviewer/opcode_generator.py (Diff revision 1)
     
     
     
    Show all issues

    Looks like there's an off-by-one alignment issue here.

  14. reviewboard/diffviewer/opcode_generator.py (Diff revision 1)
     
     
     
     
     
    Show all issues

    We can move the r_move_range = None to the else to avoid double-setting the variable.

  15. 
      
david
david
maubin
  1. 
      
  2. reviewboard/diffviewer/chunk_generator.py (Diff revision 3)
     
     
     
     
    Show all issues

    And this changed to keyword only args.

  3. Show all issues

    Why can't we just give imeta a type of only dict[str, Any], since we always assert it to be non-None.

    1. This is called by unpacking DiffOpcodeWithMetadata instances. For some opcodes (such as equal), it's valid to have None for the metadata field. For codepaths leading to this method, we will have always set a metadata dict, and so we assert here.

      We can't change the type here without either updating DiffOpcodeWithMetadata to require a non-None metadata field (which is wasteful) or by unpacking and doing the assertion elsewhere.

  4. 
      
david
Review request changed
Commits:
Summary ID
Modernize the rest of chunk and opcode generators and differ base.
This change finishes up modernization of the `chunk_generator`, `differ`, and `opcode_generator` files in the diffviewer. For the most part this just involves fixing up docstrings and adding type hints. The one functional change in here is a fix for a subtle bug that I discovered when working through this: when computing headers, we were subtracting 1 from the end line numbers of the chunk twice: once in `_new_chunk`, and once in `_get_interesting_headers`. This meant we'd stop iterating one line too soon. We obviously didn't notice any bugs in practice, but it's possible that it was affecting the header computation, especially for chunks that are only a single line. Testing Done: - Ran unit tests. - Smoke tested a bunch of diffs.
zwkyoovslsqxvknqzpzmtqmpummrntmn
Modernize the rest of chunk and opcode generators and differ base.
This change finishes up modernization of the `chunk_generator`, `differ`, and `opcode_generator` files in the diffviewer. For the most part this just involves fixing up docstrings and adding type hints. The one functional change in here is a fix for a subtle bug that I discovered when working through this: when computing headers, we were subtracting 1 from the end line numbers of the chunk twice: once in `_new_chunk`, and once in `_get_interesting_headers`. This meant we'd stop iterating one line too soon. We obviously didn't notice any bugs in practice, but it's possible that it was affecting the header computation, especially for chunks that are only a single line. Testing Done: - Ran unit tests. - Smoke tested a bunch of diffs.
zwkyoovslsqxvknqzpzmtqmpummrntmn

Checks run (2 succeeded)

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