Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-135447: Document new bytecodes in 3.14 #135803

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Yzi-Li
Copy link
Contributor

@Yzi-Li Yzi-Li commented Jun 22, 2025

Document:

  • BUILD_TEMPLATE
  • BUILD_INTERPOLATION
  • NOT_TAKEN

📚 Documentation preview 📚: https://cpython-previews--135803.org.readthedocs.build/


.. opcode:: BUILD_TEMPLATE

Create a Template object consuming interpolations and a string from the stack,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

waiting for the doc of string.templatelib

:class:`string.templatelib.Template`

@@ -1163,6 +1169,26 @@ iterations of the loop.
.. versionadded:: 3.6


.. opcode:: BUILD_INTERPOLATION

Constructs an Interpolation object from the following components, and pushes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

waiting for the doc of string.templatelib

:class:`string.templatelib.Interpolation`

@Yzi-Li Yzi-Li marked this pull request as ready for review June 22, 2025 03:42
@Yzi-Li
Copy link
Contributor Author

Yzi-Li commented Jun 22, 2025

@Fidget-Spinner I did a PR to fix the issue. I'm not sure if my expression is correct, so could you take a look? Thanks!

@Fidget-Spinner
Copy link
Member

Fidget-Spinner commented Jun 22, 2025

I think there's some misconception happening here, but no worries, I'll explain how to interpret the bytecode.

To document a new bytecode, you need to go to this file https://github.com/python/cpython/blob/main/Python/bytecodes.c . Then, find the bytecode definition (for example, inst(BUILD_INTERPOLATION). Everything after the comma and to the left of the -- are the stack inputs, everything to the right are stack outputs. So for example, inst(BUILD_INTERPOLATION, (value, str, format[oparg & 1] -- interpolation)) should be documented as:

``BUILD_INTERPOLATION`` expects as stack inputs:
* ``STACK[oparg & 1]`` should be ``format``
* ``STACK[-1 - (oparg & 1)]`` should be ``str``
* ``STACK[-2 - (oparg & 1)]`` should be ``value``

``BUILD_INTERPOLATION`` outputs the interpolation object to TOS after consuming its inputs

Based on this, are you able to infer the behavior of BUILD_TEMPLATE :) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants