Skip to content

gh-156133: Add PyUnstable_InterpreterFrame_GetLocals - #156134

Open
guilhermeleobas wants to merge 1 commit into
python:mainfrom
guilhermeleobas:guilhermeleobas/frame-getlocals
Open

gh-156133: Add PyUnstable_InterpreterFrame_GetLocals#156134
guilhermeleobas wants to merge 1 commit into
python:mainfrom
guilhermeleobas:guilhermeleobas/frame-getlocals

Conversation

@guilhermeleobas

@guilhermeleobas guilhermeleobas commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Add an unstable C API that reads a frame's local variables into a caller-provided array indexed by localsplus index, with cell and free variables unboxed to their contents. Free variables are resolved from the function closure, so the API also works on a frame that has not started executing (before COPY_FREE_VARS runs), which is the case that motivated it.

Includes the three PEP 689 deliverables:

  1. reference documentation in Doc/c-api/frame.rst
  2. a What's New entry for 3.15
  3. and tests (a C wrapper in Modules/_testinternalcapi.c driven by Lib/test/test_capi/test_frame_getlocals.py covering plain locals, a cell variable, and a free variable).

Authored with the assistance of an AI coding agent (Claude Opus)

@python-cla-bot

python-cla-bot Bot commented Aug 20, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Add an unstable C API that returns a strong reference to a single local
variable of an internal interpreter frame, addressed by its localsplus index,
with cell and free variables unboxed to their contents. Free variables are
resolved from the function closure, so the API also works on a frame that has
not started executing (before COPY_FREE_VARS runs) -- the case that motivated
it -- and it does not modify the frame.

Includes the PEP 689 deliverables: reference documentation in
Doc/c-api/frame.rst, a What's New entry for 3.16, a Misc/NEWS.d blurb, and
tests in Lib/test/test_capi/test_misc.py (TestInternalFrameApi) covering plain
locals, a cell variable, and a free variable.

Authored with the assistance of an AI coding agent (Claude Opus)
@guilhermeleobas
guilhermeleobas force-pushed the guilhermeleobas/frame-getlocals branch from 049e1b3 to 9145c2f Compare August 20, 2026 19:16
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34160350 | 📁 Comparing 9145c2f against main (83531fd)

  🔍 Preview build  

3 files changed
± c-api/frame.html
± whatsnew/3.16.html
± whatsnew/changelog.html

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.

1 participant