gh-142250: Add hasjforward and hasjback collections to opcode.py and document in dis.rst #142281
+41
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add new opcode collections
hasjforwardandhasjbackto distinguish between forward and backward jump instructions, addressing the needs of third-party bytecode libraries.Change :
(1)
Lib/opcode.pyhasjforwardandhasjbackto__all__exports_is_backward_jump_op()helper functionhasjforwardcollection (12 forward jump opcodes)hasjbackcollection (4 backward jump opcodes:JUMP_BACKWARD,JUMP_BACKWARD_NO_INTERRUPT,FOR_ITER,END_ASYNC_FOR)(2)
Doc/library/dis.rsthasjforwardcollection with.. versionadded:: 3.14hasjbackcollection with examples includingEND_ASYNC_FORfor testing :
./python.exe -c "from opcode import hasjforward, hasjback; print('hasjforward:', len(hasjforward)); print('hasjback:', len(hasjback))"
Output: hasjforward: 12, hasjback: 4
./python.exe -c "from opcode import hasjback, opmap, opname; print([opname[op] for op in hasjback])"
Output: ['END_ASYNC_FOR', 'FOR_ITER', 'JUMP_BACKWARD', 'JUMP_BACKWARD_NO_INTERRUPT']
./python.exe -m test test_dis
Result: PASSED
issue #142250
📚 Documentation preview 📚: https://cpython-previews--142281.org.readthedocs.build/