Skip to content

bpo-40222: update doc entry with respect to the change in WITH_EXCEPT… #29975

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

Merged
merged 1 commit into from
Dec 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -584,12 +584,14 @@ iterations of the loop.

.. opcode:: WITH_EXCEPT_START

Calls the function in position 7 on the stack with the top three
Calls the function in position 8 on the stack with the top three
items on the stack as arguments.
Used to implement the call ``context_manager.__exit__(*exc_info())`` when an exception
has occurred in a :keyword:`with` statement.

.. versionadded:: 3.9
.. versionchanged:: 3.11
The ``__exit__`` function is in position 8 of the stack rather than 7.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing. What is in positions 4-7, and how does that compare to what was in positions 4-6 before?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment next to the opcode in ceval.c spells it out. Used to be exit, tb, val, exc, tb, val, exc (two exceptions). Now it's exit, lasti, tb, val, exc, tb, val, exc. because the previous exceptions needs to know what the last line was. This lasti business was added with zero-cost exceptions, I'm not totally clear about when it is or is not there.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I wonder why we bother to document these opcodes when the documentation is so blatantly insufficient. :-(

FWIW that comment in the code is not great either -- "Then we push again the TOP exception and the __exit__ return value." But TOP was never popped, so we really only push the return value. I'm guessing you will soon change this again so that there are just two exception objects on the top of the stack.

(I find the opcode name also odd. Why START when it calls __exit__?)

Anyway. Ignore me.



.. opcode:: POP_EXCEPT_AND_RERAISE
Expand Down