-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Open
Labels
3.12only security fixesonly security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
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
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error