dis.cmp_op doc is inaccurate in Python 3.12.2 and 3.13.0a5
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 77.2k
- Forks
- 35.9k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der Dokumentation zu dis.cmp_op und dem gemeldeten dis.get_instructions()-Beispiel und vergleiche anschließend das Verhalten von Python 3.12 und 3.13 mit Python 3.11. Prüfe die verlinkten PRs gh-117272 und gh-117274 auf die aktuelle Richtung; abgeschlossen ist die Aufgabe, wenn die Dokumentation die Suche nach Vergleichsoperationen und den verfügbaren Workaround korrekt erklärt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 25/100