A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/nedbat/coveragepy/issues/1991 below:

KeyError in sysmon_branch_either · Issue #1991 · nedbat/coveragepy · GitHub

Describe the bug

Running the bytecode testsuite (code in this PR MatthieuDartiailh/bytecode#166) on Python 3.14b3 with coverage leads to the following error. Note that the tests pass when disabling coverage measurement:

_______________________________________ DumpCodeTests.test_concrete_bytecode ________________________________________ 

self = <tests.test_misc.DumpCodeTests testMethod=test_concrete_bytecode>

    def test_concrete_bytecode(self):
        source = """
            def func(test):
                if test == 1:
                    return 1
                elif test == 2:
                    return 2
                return 3
        """
>       code = disassemble(source, function=True)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests\test_misc.py:528:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
tests\__init__.py:143: in disassemble
    return Bytecode.from_code(code)
           ^^^^^^^^^^^^^^^^^^^^^^^^
src\bytecode\bytecode.py:281: in from_code
    concrete = _bytecode.ConcreteBytecode.from_code(code)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
src\bytecode\concrete.py:353: in from_code
    for _, size, _ in (i.cache_info or ()) if PY313 else ():  # type: ignore
                       ^^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <SysMonitor at 0x209418ac440: 6910 data points in 19 files>
code = <code object from_code at 0x000002093F8F0DC0, file "C:\Users\DartiailhMatthieu\Documents\Coding\Projects\bytecode\src\bytecode\concrete.py", line 332>
instruction_offset = 398, destination_offset = 408

    @panopticon("code", "@", "@")
    def sysmon_branch_either(
        self, code: CodeType, instruction_offset: TOffset, destination_offset: TOffset
    ) -> MonitorReturn:
        """Handle BRANCH_RIGHT and BRANCH_LEFT events."""
        if self.stats is not None:
            self.stats["branches"] += 1
        code_info = self.code_infos[id(code)]
        # code_info is not None and code_info.file_data is not None, since we
        # wouldn't have enabled this event if they were.
        if not code_info.branch_trails:
            if self.stats is not None:
                self.stats["branch_trails"] += 1
            code_info.branch_trails = branch_trails(code)
            # log(f"branch_trails for {code}:\n    {code_info.branch_trails}")
        added_arc = False
        dest_info = code_info.branch_trails.get(instruction_offset)
        # log(f"{dest_info = }")
        if dest_info is not None:
            for offsets, arc in dest_info:
                if arc is None:
                    continue
                if destination_offset in offsets:
                    code_info.file_data.add(arc)  # type: ignore
                    # log(f"adding {arc=}")
                    added_arc = True
                    break

        if not added_arc:
            # This could be an exception jumping from line to line.
            assert code_info.byte_to_line is not None
            l1 = code_info.byte_to_line[instruction_offset]
>           l2 = code_info.byte_to_line[destination_offset]
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E           KeyError: 408

.venv\Lib\site-packages\coverage\sysmon.py:451: KeyError

To Reproduce
How can we reproduce the problem? Please be specific. Don't link to a failing CI job. Answer the questions below:

  1. What version of Python are you using? 3.14b3
  2. What version of coverage.py shows the problem? Coverage 7.9.1 with pytest-cov 6.2.1
  3. What versions of what packages do you have installed?
    cachetools==6.1.0
    chardet==5.2.0
    colorama==0.4.6
    coverage==7.9.1
    distlib==0.3.9
    filelock==3.18.0
    iniconfig==2.1.0
    mypy==1.16.1
    mypy-extensions==1.1.0
    packaging==25.0
    pathspec==0.12.1
    platformdirs==4.3.8
    pluggy==1.6.0
    pygments==2.19.2
    pyproject-api==1.9.1
    pytest==8.4.1
    pytest-cov==6.2.1
    ruff==0.12.0
    tox==4.27.0
    typing-extensions==4.14.0
    virtualenv==20.31.2
  4. What code shows the problem? https://github.com/MatthieuDartiailh/bytecode, commit f9389243a5710b9e0f20979f8a19acbef66d451d
  5. What commands should we run to reproduce the problem?

Expected behavior
No exception should be raised.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4