gh-142250: Add hasjforward and hasjback collections to opcode.py and document in dis.rst#142281
gh-142250: Add hasjforward and hasjback collections to opcode.py and document in dis.rst#142281khanak0509 wants to merge 6 commits intopython:mainfrom
Conversation
…y and document in dis.rst
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
MatthieuDartiailh
left a comment
There was a problem hiding this comment.
The News fragment should mention the fix to the END_ASYNC_FOR documentation.
Also while the fix should be backported to 3.14, the addition of the hasjforward is unlikely to be so it may be better to split the work in two.
|
I have added News fragment to the END_ASYNC_FOR documentation in latest commit but what do you mean by "Also while the fix should be backported to 3.14, the addition of the hasjforward is unlikely to be so it may be better to split the work in two." |
|
@MatthieuDartiailh could you please review it ? |
MatthieuDartiailh
left a comment
There was a problem hiding this comment.
One small comment. However I have no authority to approve/merge this.
| return op_name in ( | ||
| 'JUMP_BACKWARD', | ||
| 'JUMP_BACKWARD_NO_INTERRUPT', | ||
| 'FOR_ITER', |
There was a problem hiding this comment.
From https://docs.python.org/3/library/dis.html#opcode-FOR_ITER FOR_ITER is a forward jump
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/