Skip to content

Conversation

@khanak0509
Copy link

@khanak0509 khanak0509 commented Dec 5, 2025

Add new opcode collections hasjforward and hasjback to distinguish between forward and backward jump instructions, addressing the needs of third-party bytecode libraries.

Change :

(1) Lib/opcode.py

  • Added hasjforward and hasjback to __all__ exports
  • Implemented _is_backward_jump_op() helper function
  • Created hasjforward collection (12 forward jump opcodes)
  • Created hasjback collection (4 backward jump opcodes: JUMP_BACKWARD, JUMP_BACKWARD_NO_INTERRUPT, FOR_ITER, END_ASYNC_FOR)

(2) Doc/library/dis.rst

  • Documented hasjforward collection with .. versionadded:: 3.14
  • Documented hasjback collection with examples including END_ASYNC_FOR

for 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/

@python-cla-bot
Copy link

python-cla-bot bot commented Dec 5, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Dec 5, 2025

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 skip news label instead.

Copy link
Contributor

@MatthieuDartiailh MatthieuDartiailh left a 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.

@khanak0509
Copy link
Author

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."
could you please elaborate . do I have to create two PR for each change one for dis.rst and second for opcode.py ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants