Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort blocks by line number of the first opcode #1786

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Commits on Sep 27, 2024

  1. Sort blocks by line number of the first opcode

    Blocks are sorted by number of predecessors. Previously the index of the first opcode, i.e. the order in the bytecode, served as a tie breaker.
    
    In Python 3.12 the added test case fails with:
    
        dummy_input_file:10:3: error: in <module>: None [assert-type]
          Expected: Optional[str]
            Actual: None
    
          assert_type(err, str|None)
          ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    Python 3.12 emits the bytecode for the `except` block last for some reason.
    
    Because of the while loop, every block is a predecessor of every other block, and the predecessor-based sorting fails. It falls back to the tie breaker and pytype executes the `except` block last, i.e. after `assert_type`. By the time pytype executes `assert_type` it don't know about the possible `str` type.
    
    This change uses the line number of the first opcode as a tie breaker first and then falls back to the index.
    
    PiperOrigin-RevId: 679166584
    frigus02 authored and copybara-github committed Sep 27, 2024
    Configuration menu
    Copy the full SHA
    443a764 View commit details
    Browse the repository at this point in the history