@@ -287,8 +287,9 @@ returns a write-through proxy to the frame's local and locally referenced
287
287
nonlocal variables in these scopes, rather than returning an inconsistently
288
288
updated shared ``dict `` instance with undefined runtime semantics.
289
289
290
- See :pep: `667 ` for more details, including related C API changes and
291
- deprecations.
290
+ See :pep: `667 ` for more details, including related C API changes and deprecations. Porting
291
+ notes are also provided below for the affected :ref: `Python APIs <pep667-porting-notes-py >`
292
+ and :ref: `C APIs <pep667-porting-notes-c >`.
292
293
293
294
(PEP and implementation contributed by Mark Shannon and Tian Gao in
294
295
:gh: `74929 `. Documentation updates provided by Guido van Rossum and
@@ -2234,6 +2235,8 @@ Changes in the Python API
2234
2235
returned by :meth: `zipfile.ZipFile.open ` was changed from ``'r' `` to ``'rb' ``.
2235
2236
(Contributed by Serhiy Storchaka in :gh: `115961 `.)
2236
2237
2238
+ .. _pep667-porting-notes-py :
2239
+
2237
2240
* Calling :func: `locals ` in an :term: `optimized scope ` now produces an
2238
2241
independent snapshot on each call, and hence no longer implicitly updates
2239
2242
previously returned references. Obtaining the legacy CPython behaviour now
@@ -2329,15 +2332,27 @@ Changes in the C API
2329
2332
to :c:func: `PyUnstable_Code_GetFirstFree `.
2330
2333
(Contributed by Bogdan Romanyuk in :gh: `115781 `.)
2331
2334
2332
- * Calling :c:func: `PyFrame_GetLocals ` or :c:func: `PyEval_GetLocals ` in an
2333
- :term: `optimized scope ` now returns a write-through proxy rather than a
2334
- snapshot that gets updated at ill-specified times. If a snapshot is desired,
2335
- it must be created explicitly (e.g. with :c:func: `PyDict_Copy `) or by calling
2336
- the new :c:func: `PyEval_GetFrameLocals ` API. (Changed as part of :pep: `667 `.)
2335
+ .. _pep667-porting-notes-c :
2336
+
2337
+ * The effects of mutating the dictionary returned from :c:func: `PyEval_GetLocals ` in an
2338
+ :term: `optimized scope ` have changed. New dict entries added this way will now *only * be
2339
+ visible to subsequent :c:func: `PyEval_GetLocals ` calls in that frame, as
2340
+ :c:func: `PyFrame_GetLocals `, :func: `locals `, and
2341
+ :attr: `FrameType.f_locals <frame.f_locals> ` no longer access the same underlying cached
2342
+ dictionary. Changes made to entries for actual variable names and names added via the
2343
+ write-through proxy interfaces will be overwritten on subsequent calls to
2344
+ :c:func: `PyEval_GetLocals ` in that frame. The recommended code update depends on how the
2345
+ function was being used, so refer to the deprecation notice on the function for details.
2346
+ (Changed as part of :pep: `667 `.)
2347
+
2348
+ * Calling :c:func: `PyFrame_GetLocals ` in an :term: `optimized scope ` now returns a
2349
+ write-through proxy rather than a snapshot that gets updated at ill-specified times.
2350
+ If a snapshot is desired, it must be created explicitly (e.g. with :c:func: `PyDict_Copy `)
2351
+ or by calling the new :c:func: `PyEval_GetFrameLocals ` API. (Changed as part of :pep: `667 `.)
2337
2352
2338
2353
* :c:func: `!PyFrame_FastToLocals ` and :c:func: `!PyFrame_FastToLocalsWithError `
2339
2354
no longer have any effect. Calling these functions has been redundant since
2340
- Python 3.11, when :c:func: `PyFrame_GetLocals ` was first introduced.
2355
+ Python 3.11, when :c:func: `PyFrame_GetLocals ` was first introduced.
2341
2356
(Changed as part of :pep: `667 `.)
2342
2357
2343
2358
* :c:func: `!PyFrame_LocalsToFast ` no longer has any effect. Calling this function
@@ -2497,6 +2512,11 @@ Deprecated C APIs
2497
2512
:c:func: `PyWeakref_GetRef ` on Python 3.12 and older.
2498
2513
(Contributed by Victor Stinner in :gh: `105927 `.)
2499
2514
2515
+ * Deprecate the :c:func: `PyEval_GetBuiltins `, :c:func: `PyEval_GetGlobals `, and
2516
+ :c:func: `PyEval_GetLocals ` functions, which return a :term: `borrowed reference `.
2517
+ Refer to the deprecation notices on each function for their recommended replacements.
2518
+ (Soft deprecated as part of :pep: `667 `.)
2519
+
2500
2520
Pending Removal in Python 3.14
2501
2521
------------------------------
2502
2522
0 commit comments