[3.13] gh-118888: Further PEP 667 docs updates (gh-119894)

* Clarify impact on default behaviour of exec, eval, etc
* Update documentation for changes to PyEval_GetLocals (gh-74929)

Closes gh-118888
(cherry picked from commit 2180991ea3)

Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-06-02 07:41:25 +02:00 committed by GitHub
parent edb6883ef3
commit 36ca00f44d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 44 additions and 3 deletions

View file

@ -19,11 +19,24 @@ Reflection
.. deprecated:: 3.13
Use :c:func:`PyEval_GetFrameLocals` instead.
To avoid creating a reference cycle in :term:`optimized scopes <optimized scope>`,
use either :c:func:`PyEval_GetFrameLocals` to obtain the same behaviour as calling
:func:`locals` in Python code, or else call :c:func:`PyFrame_GetLocals` on the result
of :c:func:`PyEval_GetFrame` to get the same result as this function without having to
cache the proxy instance on the underlying frame.
Return a dictionary of the local variables in the current execution frame,
Return the :attr:`~frame.f_locals` attribute of the currently executing frame,
or ``NULL`` if no frame is currently executing.
If the frame refers to an :term:`optimized scope`, this returns a
write-through proxy object that allows modifying the locals.
In all other cases (classes, modules, :func:`exec`, :func:`eval`) it returns
the mapping representing the frame locals directly (as described for
:func:`locals`).
.. versionchanged:: 3.13
As part of :pep:`667`, return a proxy object for optimized scopes.
.. c:function:: PyObject* PyEval_GetGlobals(void)
@ -57,6 +70,10 @@ Reflection
or ``NULL`` if no frame is currently executing. Equivalent to calling
:func:`locals` in Python code.
To access :attr:`~frame.f_locals` on the current frame without making an independent
snapshot in :term:`optimized scopes <optimized scope>`, call :c:func:`PyFrame_GetLocals`
on the result of :c:func:`PyEval_GetFrame`.
.. versionadded:: 3.13