-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
gh-142250: Add hasjforward and hasjback collections to opcode.py and document in dis.rst #142281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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/