Skip to content

Commit 9c13d9e

Browse files
authored
gh-74929: Rudimentary docs for PEP 667 (#118581)
This is *not* sufficient for the final 3.13 release, but it will do for beta 1: - What's new entry - Updated changelog entry (news blurb) - Mention the proxy for f_globals in the datamodel and Python frame object docs This doesn't have any C API details (what's new refers to the PEP).
1 parent 5a0022a commit 9c13d9e

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

Doc/c-api/frame.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,19 @@ See also :ref:`Reflection <reflection>`.
120120
121121
.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)
122122
123-
Get the *frame*'s :attr:`~frame.f_locals` attribute (:class:`dict`).
123+
Get the *frame*'s :attr:`~frame.f_locals` attribute.
124+
If the frame refers to a function or comprehension, this returns
125+
a write-through proxy object that allows modifying the locals.
126+
In all other cases (classes, modules) it returns the :class:`dict`
127+
representing the frame locals directly.
124128
125129
Return a :term:`strong reference`.
126130
127131
.. versionadded:: 3.11
128132
133+
.. versionchanged:: 3.13
134+
Return a proxy object for functions and comprehensions.
135+
129136
130137
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)
131138

Doc/reference/datamodel.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,12 @@ Special read-only attributes
13411341

13421342
* - .. attribute:: frame.f_locals
13431343
- The dictionary used by the frame to look up
1344-
:ref:`local variables <naming>`
1344+
:ref:`local variables <naming>`.
1345+
If the frame refers to a function or comprehension,
1346+
this may return a write-through proxy object.
1347+
1348+
.. versionchanged:: 3.13
1349+
Return a proxy for functions and comprehensions.
13451350

13461351
* - .. attribute:: frame.f_globals
13471352
- The dictionary used by the frame to look up

Doc/whatsnew/3.13.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ Interpreter improvements:
8787
Performance improvements are modest -- we expect to be improving this
8888
over the next few releases.
8989

90+
* :pep:`667`: :attr:`FrameType.f_locals <frame.f_locals>` when used in
91+
a function now returns a write-through proxy to the frame's locals,
92+
rather than a ``dict``. See the PEP for corresponding C API changes
93+
and deprecations.
94+
9095
New typing features:
9196

9297
* :pep:`696`: Type parameters (:data:`typing.TypeVar`, :data:`typing.ParamSpec`,
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Implement PEP 667 - converted ``frame.f_locals`` to a write through proxy
1+
Implement PEP 667: converted :attr:`FrameType.f_locals <frame.f_locals>`
2+
and :c:func:`PyFrame_GetLocals` to return a write-through proxy object
3+
when the frame refers to a function or comprehension.

0 commit comments

Comments
 (0)