Skip to content

Fix LOAD_COMMON_CONSTANT argrepr behavior on 3.15#191

Merged
rocky merged 2 commits into
rocky:masterfrom
Quinntyx:fix/load-common-constant
Jul 22, 2026
Merged

Fix LOAD_COMMON_CONSTANT argrepr behavior on 3.15#191
rocky merged 2 commits into
rocky:masterfrom
Quinntyx:fix/load-common-constant

Conversation

@Quinntyx

Copy link
Copy Markdown
Contributor

On 3.15, argrepr in dis has been adjusted to the actual LOAD_COMMON_CONSTANT values, unlike 3.14 where they are still integers. This causes a parity mismatch between xdis and dis on 3.15.

This PR fixes this parity issue by adding a hook in bytecode.py and updating opcode_315.py to use LOAD_COMMON_CONSTANT values for argval, and changing argrepr to use repr(argval) to avoid the need for 2 LOAD_COMMON_CONSTANT tables.

Issue reproduction

import dis
import sys
from xdis import Bytecode, get_opcode

code = compile(
    'result = {"success": True, "failure": False}',
    "<test>",
    "exec",
)

native = [
    (inst.arg, inst.argval, inst.argrepr)
    for inst in dis.get_instructions(code)
    if inst.opname == "LOAD_COMMON_CONSTANT"
]
cross = [
    (inst.arg, inst.argval, inst.argrepr)
    for inst in Bytecode(code, get_opcode(sys.version_info[:2], False))
    if inst.opname == "LOAD_COMMON_CONSTANT"
]

print("dis:", native)
print("xdis:", cross)

Output on 3.15:

dis:  [(9, True, 'True'), (10, False, 'False'), (7, None, 'None')]
xdis: [(9, 9, 'True'), (10, 10, 'False'), (7, 7, 'None')]

@rocky

rocky commented Jul 22, 2026

Copy link
Copy Markdown
Owner

This is apparently a recent addition to Python 3.15. I am not seeing it in 3.15.0a7.

LGTM though. Verified on 3.15.0b3.

@rocky
rocky merged commit 3372eba into rocky:master Jul 22, 2026
12 checks passed
@rocky

rocky commented Jul 22, 2026

Copy link
Copy Markdown
Owner

BTW. Unrelated. The other day I was listing 3.14 instructions, and I see that disassembly is not showing the argument value on a STORE_FAST. Something I'll look at when I get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants