python / python/cpython

dis.cmp_op doc is inaccurate in Python 3.12.2 and 3.13.0a5

未關閉
#117,270 6 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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

描述

Bug report

Bug description:

From https://docs.python.org/3.12/library/dis.html#opcode-COMPARE_OP,
dis.cmp_op should be able lookup the comparison operation string from the opcode's argument.
However, in Python 3.12.2 and 3.13.0a5, this fails with "IndexError: tuple index out of range"

import dis

def my_fun(a, b):
    return a <= b

for instruction in dis.get_instructions(my_fun):
    if instruction.opname == 'COMPARE_OP':
        print(dis.cmp_op[instruction.arg])

In Python 3.11.8, it prints "<=" as expected.

dis.dis output of my_fun in Python 3.12.2:

  1           0 RESUME                   0

  2           2 LOAD_FAST                0 (a)
              4 LOAD_FAST                1 (b)
              6 COMPARE_OP              26 (<=)
             10 RETURN_VALUE

dis.cmp_op in Python 3.12.2:

('<', '<=', '==', '!=', '>', '>=')

Workaround: use instruction.argrepr.

CPython versions tested on:

3.12, 3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-117272
  • gh-117274

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

先從 dis.cmp_op 文件和回報的 dis.get_instructions() 範例開始,然後將 Python 3.12 和 3.13 的行為與 Python 3.11 進行比較。檢閱連結的 PR gh-117272 和 gh-117274,以了解目前的方向;完成的標準是文件準確說明比較操作查找以及可用的 workaround。

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

評估

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

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

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