Add typing for diff opcodes.

Review Request #14418 — Created May 2, 2025 and submitted

Information

Review Board
master

Reviewers

This change updates diff opcodes to use explicitly typed tuples. The
opcodes created by the Differ implementation have a tag and ranges,
and then the opcode generator adds an additional metadata field. In the
interest of avoiding any changes, we therefore have separate definitions
for both steps.

  • Did a bunch of smoke testing of diff generation and saw that
    everything still worked correctly.
  • Ran unit tests.
Summary ID
Add typing for diff opcodes.
This change updates diff opcodes to use explicitly typed tuples. The opcodes created by the `Differ` implementation have a tag and ranges, and then the opcode generator adds an additional metadata field. In the interest of avoiding any changes, we therefore have separate definitions for both steps. Testing Done: - Did a bunch of smoke testing of diff generation and saw that everything still worked correctly. - Ran unit tests.
f8ad232f1ebd19142135457de29d0b3156da9519
Description From Last Updated

'typing.Any' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

While here, can you put these in parens?

chipx86chipx86

Module path is missing a ..

chipx86chipx86

Can we put that back in alphabetical order?

chipx86chipx86

For this case, I'm pretty sure a tuple is actually faster. A set doesn't buy us anything. Especially constructed every …

chipx86chipx86

While we're cleaning this up, can we pull out groups, inserts, removes, and differ into local variables, so we don't …

chipx86chipx86

Same note about the tuple vs. set.

chipx86chipx86

Same as above.

chipx86chipx86

Same as above.

chipx86chipx86
There are no open issues
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

david
david
chipx86
  1. 
      
  2. reviewboard/diffviewer/myersdiff.py (Diff revision 3)
     
     
     
     
     
    Show all issues

    While here, can you put these in parens?

  3. Show all issues

    Module path is missing a ..

  4. reviewboard/diffviewer/opcode_generator.py (Diff revision 3)
     
     
     
     
     
     
    Show all issues

    Can we put that back in alphabetical order?

  5. Show all issues

    For this case, I'm pretty sure a tuple is actually faster. A set doesn't buy us anything. Especially constructed every time we do the check.

    1. Ran a test on 4M checks, averaged across 20 runs. Sets are 13% faster. Both are extremely fast, though.

  6. Show all issues

    While we're cleaning this up, can we pull out groups, inserts, removes, and differ into local variables, so we don't incur the lookup costs per-iteration?

  7. Show all issues

    Same note about the tuple vs. set.

  8. reviewboard/diffviewer/processors.py (Diff revision 3)
     
     
    Show all issues

    Same as above.

  9. reviewboard/diffviewer/processors.py (Diff revision 3)
     
     
    Show all issues

    Same as above.

  10. 
      
david
maubin
  1. Ship It!
  2. 
      
chipx86
  1. Ship It!
  2. 
      
david
Review request changed
Status:
Completed
Change Summary:
Pushed to master (df24e42)
Loading...