python / python/cpython

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

オープン
#117,270 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

3.12 docs type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

dis.cmp_op のドキュメントと報告された dis.get_instructions() の例から始め、その後、Python 3.12 および 3.13 の動作を Python 3.11 と比較します。現在の方向性について、リンクされている PR gh-117272 と gh-117274 を確認してください。完了とは、ドキュメントで比較演算の検索と利用可能な回避策が正確に説明されていることを意味します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
documentation
issue の種類
ドキュメント
難易度
2/5
見積もり時間
1〜3時間
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。