python / python/cpython

`LOAD_SMALL_INT` has empty `argrepr` via `Bytecode`

未關閉
#140,256 8 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib type-bug
主要語言
Python
星號
77.2k
分支
35.9k
PR 合併指標
PR 指標待擷取

描述

Bug report

Bug description:

When using Bytecode to disassemble some Python code I've noticed that the argrepr attribute of the Instruction holding a LOAD_SMALL_INT isn't populated. For example:

Python 3.14.0 (main, Oct 16 2025, 09:17:39) [Clang 17.0.0 (clang-1700.3.19.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from dis import Bytecode
>>> list(Bytecode("1"))
[
    Instruction(
        opname='RESUME',
        opcode=128,
        arg=0,
        argval=0,
        argrepr='',
        offset=0,
        start_offset=0,
        starts_line=True,
        line_number=0,
        label=None,
        positions=Positions(lineno=0, end_lineno=1, col_offset=0, end_col_offset=0),
        cache_info=None
    ),
    Instruction(
        opname='LOAD_SMALL_INT',
        opcode=94,
        arg=1,
        argval=1,
        argrepr='',     # <--- Empty string
        offset=2,
        start_offset=2,
        starts_line=True,
        line_number=1,
        label=None,
        positions=Positions(lineno=1, end_lineno=1, col_offset=0, end_col_offset=1),
        cache_info=None
    ),
    Instruction(
        opname='RETURN_VALUE',
        opcode=35,
        arg=None,
        argval=None,
        argrepr='',
        offset=4,
        start_offset=4,
        starts_line=False,
        line_number=1,
        label=None,
        positions=Positions(lineno=1, end_lineno=1, col_offset=0, end_col_offset=1),
        cache_info=None
    )
]

I would have expected this to have the repr of the argument in there.

A quick and ignorant reading of dis.py suggests to me that there should be a change akin to this:

--- ../cpython/Lib/dis.py       2025-10-17 14:31:35.495151419 +0100
+++ my/dis.py   2025-10-17 14:43:26.650409153 +0100
@@ -586,7 +586,7 @@
             #    _disassemble_bytes needs the string repr of the
             #    raw name index for LOAD_GLOBAL, LOAD_CONST, etc.
             argval = arg
-            if deop in hasconst:
+            if deop in hasconst or deop == LOAD_SMALL_INT:
                 argval, argrepr = _get_const_info(deop, arg, self.co_consts)
             elif deop in hasname:
                 if deop == LOAD_GLOBAL:
CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs
  • gh-140258

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 Lib/dis.py 中 Bytecode 的引數處理邏輯開始,並使用 list(Bytecode("1")) 重現該範例。檢查 LOAD_SMALL_INT 路徑和 _get_const_info 的行為;完成的標準是其 Instruction 具有預期的非空 argrepr,並根據連結的 gh-140258 工作檢查行為。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
devtools
Issue 類型
缺陷
難度
2/5
預估耗時
1-3 小時
活躍度
停滯
描述清晰度
描述清楚
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。